我有一个显示项目列表的 ListActivity
。我准备了另一个 layout
用于包含项目名称、地址、电话号码和图像的详细 View 。如果在不关闭我的 ListActivity
的情况下单击其中一项,我想在弹出窗口中显示这些项目的详细信息。
我该怎么做?
最佳答案
您可以使用 AlertDialog 来执行此操作。看这里http://developer.android.com/guide/topics/ui/dialogs.html .并滚动到创建自定义对话框。例子是:
AlertDialog.Builder builder;
AlertDialog alertDialog;
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog,
(ViewGroup) findViewById(R.id.layout_root));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Hello, this is a custom dialog!");
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.android);
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
alertDialog = builder.create();
关于android - 如何在弹出窗口中打开 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4805845/