2014-12-19 94 views
0

我正在處理菜單 - > SubMenus導航和我正面臨一個問題。與ListView自定義AlertDialog

我的第一個屏幕是一個需要所有屏幕的ListView,我希望當選擇一個ListItem時,它會轉到另一個活動,但帶有一個AlertDialog,它由一個ListView構成,它的高度爲屏幕的一半。所以當用戶點擊對話框時,它就消失了。

因此我知道如何在第一個ListView上設置一個Listener,然後跳轉到另一個Activity,從所選項目中傳遞數據以獲得填充了AsyncTask的Dialog的ListView,但我不知道如何獲取此AlertDialog由一個ListView組成

任何人都可以幫助我嗎?

乾杯

+1

你做了什麼 – 2014-12-19 09:42:41

回答

0

您將需要使用自定義對話框這樣

 final Dialog dialog = new Dialog(context); 
     dialog.setContentView(R.layout.custom); 
     dialog.setTitle("Title..."); 

     // set the custom dialog components - text, image and button 
     TextView text = (TextView) dialog.findViewById(R.id.text); 
     text.setText("Android custom dialog example!"); 
     ImageView image = (ImageView) dialog.findViewById(R.id.image); 
     image.setImageResource(R.drawable.ic_launcher); 

     Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK); 
     // if button is clicked, close the custom dialog 
     dialogButton.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       dialog.dismiss(); 
      } 
     }); 

     dialog.show(); 

注意在R.layout.custom插入一個ListView