简体   繁体   中英

How to open an activity in a popup window?

I have a ListActivity which shows list of items. I prepared another layout for detailed view that contains items' name, address, phone number and image. I want to show these items detailed in a popup window if one is clicked without closing my ListActivity .

How can i do that?

You can use AlertDialog to do this. Look here http://developer.android.com/guide/topics/ui/dialogs.html . And scroll to Creating a Custom Dialog. Example is:

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();

你可以像Twitter应用程序一样使用quickAction,或者在你的清单中指定android:theme="@android:style/Theme.Dialog"开始一个新的Activity

此页面描述了创建对话框: http//developer.android.com/guide/topics/ui/dialogs.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM