【问题标题】:Custom AlertDialog with ListView使用 ListView 自定义 AlertDialog
【发布时间】:2014-12-19 18:52:27
【问题描述】:
我正在处理菜单 -> 子菜单导航,我遇到了问题。
我的第一个屏幕是一个占据所有屏幕的 ListView,我想要的是,当一个 ListItem 被选中时,它会转到另一个活动,但 AlertDialog 由一个占据屏幕一半高度的 ListView 组成。因此,当用户点击对话框时,它就会消失。
所以我知道如何在第一个 ListView 上设置侦听器,跳转到另一个 Activity,传递来自所选项目的数据,以便让 Dialog 的 ListView 填充 AsyncTask,但我不知道如何让这个 AlertDialog 组成一个列表视图
谁能帮帮我?
干杯
【问题讨论】:
标签:
android
listview
android-listview
【解决方案1】:
你需要像这样使用自定义对话框
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom);
dialog.setTitle("Title...");
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Android custom dialog example!");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.ic_launcher);
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
注意在 R.layout.custom 中插入一个列表视图