2011-01-26 31 views
6

Tôi có một ListActivity hiển thị danh sách các mục. Tôi đã chuẩn bị một layout khác để xem chi tiết có chứa tên, địa chỉ, số điện thoại và hình ảnh của mặt hàng. Tôi muốn hiển thị các mục này chi tiết trong cửa sổ bật lên nếu một mục được nhấp mà không đóng ListActivity của tôi.Làm cách nào để mở một hoạt động trong cửa sổ bật lên?

Tôi có thể làm điều đó bằng cách nào?

Trả lời

5

Bạn có thể sử dụng AlertDialog để làm điều này. Nhìn ở đây http://developer.android.com/guide/topics/ui/dialogs.html. Và cuộn đến Tạo hộp thoại tùy chỉnh. Ví dụ:

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

'mContext = getApplicationContext();' nguyên nhân ngoại lệ. Sử dụng 'YourActivity.this' thay vì tôi tin rằng đây là lỗi được báo cáo – Onimusha

4

Bạn có thể sử dụng quickAction like the Twitter app hoặc bắt đầu Activity mới với android:theme="@android:style/Theme.Dialog" được chỉ định trong tệp kê khai của mình.

Các vấn đề liên quan