У меня есть приложение для Android, где я хочу предложить пользователю выбрать порядок столов, используя разные поля. Я использовал диалог с тремя переключателями, чтобы предложить выбор каждого типа сортировки.
Ниже приведен код в диалоговом коде, который объявляет переключатели
LayoutInflater layoutInflater = (LayoutInflater)
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View layout = layoutInflater.inflate(R.layout.lectindex_dialog, (ViewGroup) findViewById(R.id.lect_index));
builder.setView(layout);
// Now configure the AlertDialog
builder.setTitle(R.string.exindex_title);
final RadioButton radio_date = (RadioButton) findViewById(R.id.RBdate);
final RadioButton radio_loctn = (RadioButton) findViewById(R.id.RBloctn);
final RadioButton radio_stream = (RadioButton) findViewById(R.id.RBstream);
radio_date.setOnClickListener(radio_listener);
radio_loctn.setOnClickListener(radio_listener);
radio_stream.setOnClickListener(radio_listener);
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// We forcefully dismiss and remove the Dialog, so it cannot be used again (no cached info)
LecturesActivity.this.removeDialog(SELINDEX_DIALOG_ID);
}
});
Код для radio_listener объявлен отдельно, как и
private OnClickListener radio_listener = new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
RadioButton rb = (RadioButton) v;
Toast.makeText(LecturesActivity.this, rb.getText(), Toast.LENGTH_SHORT).show();
}
};
Кажется, все работает нормально, но код для radio_listener так и не используется. Почему?