2011-01-26 39 views
6

私はListActivityに項目のリストを表示しています。アイテムの名前、住所、電話番号、イメージを含む詳細ビュー用に別のlayoutを用意しました。私はListActivityを閉じずにクリックすると、これらのアイテムをポップアップウィンドウに詳細に表示します。ポップアップウィンドウでアクティビティを開くにはどうすればよいですか?

どうすればいいですか?

答えて

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

mContext = getApplicationContext(); '例外が発生します。代わりに 'YourActivity.this'を使ってください。これは報告されているバグだと思います – Onimusha

関連する問題