如何在弹出窗口中打开活动?

wet*_*ork 6 layout android android-activity

我有一个ListActivity显示项目列表.我准备了另一个layout详细视图,其中包含项目的名称,地址,电话号码和图像.如果在没有关闭我的情况下单击一个项目,我想在弹出窗口中显示这些项目ListActivity.

我怎样才能做到这一点?

Mac*_*rse 5

您可以使用像 Twitter 应用程序这样的快速操作,或者按照清单中指定的Activity方式启动新操作。android:theme="@android:style/Theme.Dialog"


Ami*_*far 5

您可以使用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();
Run Code Online (Sandbox Code Playgroud)