2014-12-19 108 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