貼個自定義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>

 

 

 

 


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章