我拼命想让我的listView打开一个警告对话框或一个充满信息的普通对话框。我似乎无法让它工作。我希望它显示不同的信息,具体取决于点击列表中的哪个项目
public class learn_tab1 extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item,
BASICLIST));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
AlertDialog dialog = new AlertDialog.Builder(this).create();
dialog.setCancelable(false);
dialog.setTitle("Instructions");
dialog.setIcon(R.drawable.bone_icon);
dialog.setMessage("test");
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "Done", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
finish();
}
});
dialog.show();
}
}
});
}
答案 0 :(得分:1)
尝试new AlertDialog.Builder(learn_tab1.this).create()
;而不是new AlertDialog.Builder(this).create()
。
我想知道它是如何得到遵守的......
修改强>
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String item = (String)parent.getItemAtPosition(position);
// ...
dialog.setMessage(item);
// ...
}