listview 根据选择打开警报对话框 android
我拼命地试图让我的 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();
}
}
});
}
Im desperately trying to get my listView to open an alert dialog or a normal dialog that is filled with information. I cant seem to get it to work. I want it to display different information aswell depending on which item on the list is clicked
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();
}
}
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试 new AlertDialog.Builder(learn_tab1.this).create();而不是
new AlertDialog.Builder(this).create()
。我想知道它是如何得到遵守的......
编辑
Try
new AlertDialog.Builder(learn_tab1.this).create()
; instead ofnew AlertDialog.Builder(this).create()
.I'm wondering how it ever get complied....
EDIT