贴个自定义dialog中显示ExpandableListView 的代码

	transplanttypeButton.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
				LayoutInflater layoutInflater  = TransplantActivity.this.getLayoutInflater();
				final AlertDialog dialog = new AlertDialog.Builder(TransplantActivity.this).create();
				dialog.show();
				 Window window = dialog.getWindow();
				        // *** 主要就是在这里实现这种效果的.
				        // 设置窗口的内容页面,shrew_exit_dialog.xml文件中定义view内容
				 window.setContentView(R.layout.transplanttypedialog);
				 ExpandableListView  expandablelistview  =  (ExpandableListView) window.findViewById(R.id.expandableListView1);
				 
				 
				 final ArrayList<String> groupArray = new  ArrayList<String>();   
				 final ArrayList<List<String>> childArray = new  ArrayList<List<String>>();
				
				groupArray.add("地膜");
				groupArray.add("非地膜");
				
				final ArrayList<String> temparray = new  ArrayList<String>(); 
				temparray.add("地膜井窖");
				temparray.add("地膜非井窖");        
 
				final ArrayList<String> temparray1 = new  ArrayList<String>();     
				temparray1.add("井窖"); 
				temparray1.add(" 非井窖"); 
                      
				childArray.add(temparray);
				childArray.add(temparray1);
				expandablelistview.setAdapter(new  ExpandableAdapter(TransplantActivity.this,groupArray,childArray ));
				expandablelistview.setOnChildClickListener(new OnChildClickListener() {
					
					@Override
					public boolean onChildClick(ExpandableListView parent, View v,
							int groupPosition, int childPosition, long id) {
						
						if (groupPosition==0) {
							typestring = temparray.get(childPosition);
						}
						if (groupPosition==1) {
							typestring = temparray1.get(childPosition);
						}
						dialog.dismiss();
						transplanttypeButton.setText(typestring);
						return true;
					}
				});
				}
			});
 
 
 
 
 
 

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical" >

    <TextView         android:id="@+id/textView1"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:gravity="center"         android:text="请选择移栽方式"         android:textSize="24dp" />

    <ExpandableListView         android:id="@+id/expandableListView1"         android:layout_width="match_parent"         android:layout_height="wrap_content" >     </ExpandableListView>

</LinearLayout>

 

 

 

 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值