我将 OnItemClick 攻击到了一个列表视图,并在 onItemClick() 中打开了一个带有单选按钮、取消和选择的对话框。在对话框中,我想我需要某种 clickListener 或 itemSelectedListener 以便我可以传递他们选择的 listview 项目的值。
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(position == 0) {
CheckBox checkBox = (CheckBox) mRoot.findViewById(R.id.cbRowCheckBox);
checkBox.setChecked(!checkBox.isChecked());
}
if(position == 1) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.sync_frequency);
ListView listView = new ListView(getActivity());
listView.setOnItemClickListener(new OnItemClickListener()); <-----
String[] syncOptions = mSyncOptions;
ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_singlechoice, android.R.id.text1, syncOptions);
builder.setSingleChoiceItems(modeAdapter, 0, null);
builder.setView(listView);
builder.setPositiveButton(R.string.sync_select,null);
builder.setNegativeButton(R.string.sync_cancel,null);
final Dialog dialog = builder.create();
dialog.show();
}
}
});
但我收到一条错误消息,提示无法实例化类型 AdapterView.OnItemClickListener。最好的路线是什么,或者我该如何解决这个问题,以便让代码知道用户选择了哪个单选按钮?谢谢!