Seçim listesiyle bir uyarı iletişim kutusu yapıyorum. OnClickListener değişkenimin neden çözümlenemediğini anlayamıyorum.DialogInterface.OnClickListener listener değişkeni çözümlenemiyor [java]
Kodu kendi başına ayrı bir etkinliğe koydum ve işe yarıyor ama ana etkinliğimin içinde değil.
public void categoryDialogShow(final Context context, String[] categoryOptions){
final AlertDialog actions;
DialogInterface.OnClickListener actionListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//goto category list with which as the category
}
};
AlertDialog.Builder categoryAlert = new AlertDialog.Builder(context);
categoryAlert.setTitle("Choose a Category");
categoryAlert.setItems(categoryOptions, actionListener);
categoryAlert.setNegativeButton("Cancel", null);
actions = categoryAlert.create();
actions.show();
}
diğer çalışır nedeni:
public class MainActivity extends ActionBarActivity {
AlertDialog actions;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("Activity");
Button button = new Button(this);
button.setText("Click for Options");
button.setOnClickListener(buttonListener);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Choose an Option");
String[] options = { "A", "B", "C" };
builder.setItems(options, actionListener);
builder.setNegativeButton("Cancel", null);
actions = builder.create();
setContentView(button);
}
DialogInterface.OnClickListener actionListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0: // Delete
break;
case 1: // Copy
break;
case 2: // Edit
break;
default:
break;
}
}
};
View.OnClickListener buttonListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
actions.show();
}
};
}
Evet, bildirimin taşınması. Sorgumu, kullandığım öğretici komut dosyasıyla düzenledim. Orada neden işe yarayacağını görebiliyor musun? – silversunhunter
@silversunhunter sadece cevabı güncelledi, asıl tahminim doğruydu. –
Bu bir kapsam sorunu mu? Örnekte, dialogInterface oncreate() öğesinin dışındayken, komutumda dialogInterface yöntemde yer alır. – silversunhunter