2013-01-19 3 views
0

여기 내 코드입니다. 이것은 다소 멍청한 질문입니다. 목록보기에서 하위 작업을 추가 할 수 있습니까? 이 코드는 확장 가능한 목록 뷰를 포함하고 있으며, 3 개의 자식과 내가 필요한 것은 각각의 자식을 개별적으로 클릭하면 page2.java와 같은 다른 클래스가 열립니다.확장 가능한 목록의 각 하위에 작업을 추가하려면 어떻게해야합니까?

import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 
import android.app.ExpandableListActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.ExpandableListView; 
import android.widget.SimpleExpandableListAdapter; 

public class ExpandableListDemo extends ExpandableListActivity { 

@SuppressWarnings("unchecked") 
public void onCreate(Bundle savedInstanceState) { 
    try{ 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

    SimpleExpandableListAdapter expListAdapter = 
     new SimpleExpandableListAdapter(
       this, 
       createGroupList(),    // Creating group List. 
       R.layout.group_row,    // Group item layout XML.   
       new String[] { "Group Item" }, // the key of group item. 
       new int[] { R.id.row_name }, // ID of each group item.-Data under the key goes into this TextView.     
       createChildList(),    // childData describes second-level entries. 
       R.layout.child_row,    // Layout for sub-level entries(second level). 
       new String[] {"Sub Item"},  // Keys in childData maps to display. 
       new int[] { R.id.grp_child}  // Data under the keys above go into these TextViews. 
      ); 
     setListAdapter(expListAdapter);  // setting the adapter in the list. 

    }catch(Exception e){ 
     System.out.println("Errrr +++ " + e.getMessage()); 
    } 
} 

/* Creating the Hashmap for the row */ 
@SuppressWarnings("unchecked") 
private List createGroupList() { 
     ArrayList result = new ArrayList(); 
     for(int i = 0 ; i < 15 ; ++i) { // 15 groups........ 
     HashMap m = new HashMap(); 
     m.put("Group Item","Group Item " + i); // the key and it's value. 
     result.add(m); 
     } 
     return (List)result; 
} 

/* creatin the HashMap for the children */ 
@SuppressWarnings("unchecked") 
private List createChildList() { 

    ArrayList result = new ArrayList(); 
    for(int i = 0 ; i < 15 ; ++i) { // this -15 is the number of groups(Here it's fifteen) 
     /* each group need each HashMap-Here for each group we have 3 subgroups */ 
     ArrayList secList = new ArrayList(); 
     for(int n = 0 ; n < 3 ; n++) { 
     HashMap child = new HashMap(); 
     child.put("Sub Item", "Sub Item " + n);   
     secList.add(child); 
     } 
    result.add(secList); 
    }   
    return result; 
} 
public void onContentChanged () { 
    System.out.println("onContentChanged"); 
    super.onContentChanged();   
} 
/* This function is called on each child click */ 
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,int childPosition,long id) { 
    System.out.println("Inside onChildClick at groupPosition = " + groupPosition +" Child clicked at position " + childPosition); 
    return true; 
} 

/* This function is called on expansion of the group */ 
public void onGroupExpand (int groupPosition) { 
    try{ 
     System.out.println("Group exapanding Listener => groupPosition = " + groupPosition); 
    }catch(Exception e){ 
     System.out.println(" groupPosition Errrr +++ " + e.getMessage()); 
    } 
} 

}

답변

관련 문제