これは私の非常に単純化されたバージョンですActivity
:
public class Search extends Activity {
//I need to access this.
public SearchResultsAdapter objAdapter;
public boolean onOptionsItemSelected(MenuItem itmMenuitem) {
if (itmMenuitem.getItemId() == R.id.group) {
final CharSequence[] items = {"Red", "Green", "Blue"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(itmMenuitem.getTitle());
builder.setSingleChoiceItems(lstChoices),
0, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
//I need to access it from here.
}
});
AlertDialog alert = builder.create();
alert.show();
return true;
}
}
}
メニュー ボタンを押すと、アプリケーションがAlertDialog
. AlertDialog
とインラインを作成するとonClickListener
、ダイアログ内の各項目に添付されます。objAdapater
アクティビティで定義されている変数にアクセスする必要がありますSearch
。内の検索インスタンスにonClickListener
アクセスできないため、アクセスできません。Activity
私のコードには、どこにでもインスタンスを渡すというちょっとしたスープがあります。多分私は何か間違ったことをしています。
メソッドと変数にアクセスできるように、自分の中からActivity
(Search
インスタンス)にアクセスするにはどうすればよいですか。onClickListener
ありがとうございました。