2016-02-29 126 views
0

我想在這裏擴大名單onclick可擴展標題view.But但是我陷入了爲什麼我無法顯示子列表。擴展名單不能擴大點擊

這是我的活動課。

adapter = new MyExpandableAdapter(getActivity(),parentHashMap,parentObjectCollection); 
     expandableListView.setAdapter(adapter) 
     // Listview Group expanded listener 
     expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() { 
      @Override 
      public void onGroupExpand(int groupPosition) { 
       Toast.makeText(getActivity(),  parentObjectCollection.get(groupPosition) + " Expanded", Toast.LENGTH_SHORT).show(); 
      } 
     }); 

適配器類是:

public class MyExpandableAdapter extends BaseExpandableListAdapter { 
private Context context; 
private List<String> parentObjectsCollection; 
private HashMap<String, List<MarkerInfoData>> parentHashMap; 
/* ArrayList<MarkerInfoData> child_list; 
LayoutInflater inflater;*/ 

public MyExpandableAdapter(Context context, HashMap<String, List<MarkerInfoData>> hashmap, List<String> list) { 
    parentHashMap = hashmap; 
    this.context = context; 
    this.parentHashMap = hashmap; 
    this.parentObjectsCollection = list; 
} 


@Override 
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { 
    //String childTitle = (String) getChild(groupPosition, childPosition); 
    if (convertView == null) { 
     LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE); 
     convertView = inflater.inflate(R.layout.child_row, parent, false); 
    } 
    TextView cityName = (TextView) convertView.findViewById(R.id.txtLocationcityName); 
    TextView cityAddress = (TextView) convertView.findViewById(R.id.txtLocationcityAddress); 
    TextView cityDistance = (TextView) convertView.findViewById(R.id.txtcityLocationDistanceFromCurrentLocation); 
    cityName.setText(parentHashMap.get(parentObjectsCollection.get(groupPosition)).get(childPosition).markerName); 
    cityAddress.setText(parentHashMap.get(parentObjectsCollection.get(groupPosition)).get(childPosition).markerAddress); 
    String distanceInMiles = parentHashMap.get(parentObjectsCollection.get(groupPosition)).get(childPosition).distance; 
    if (distanceInMiles != null && distanceInMiles.length() > 0) { 
     cityDistance.setText(distanceInMiles + "\nMiles"); 
    } else { 
     cityDistance.setText(""); 
    } 
    //childtextview.setText(childTitle); 

    return convertView; 
} 

@Override 
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { 
    String GroupTitle = (String) getGroup(groupPosition); 
    if (convertView == null) { 
     LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE); 
     convertView = inflater.inflate(R.layout.parent_row, parent, false); 
    } 
    TextView parenttextview = (TextView) convertView.findViewById(R.id.textviewparent); 
    parenttextview.setText(GroupTitle); 
    return convertView; 
} 

@Override 
public Object getChild(int groupPosition, int childPosition) { 
    return this.parentHashMap.get(this.parentObjectsCollection.get(groupPosition)).get(childPosition); 
} 

@Override 
public long getChildId(int groupPosition, int childPosition) { 
    return childPosition; 
} 

@Override 
public int getChildrenCount(int groupPosition) { 
    return this.parentHashMap.get(this.parentObjectsCollection.get(groupPosition)).size(); 
} 

@Override 
public Object getGroup(int groupPosition) { 
    return this.parentObjectsCollection.get(groupPosition); 
} 

@Override 
public int getGroupCount() { 
     return parentObjectsCollection.size(); 
} 


@Override 
public long getGroupId(int groupPosition) { 
    return groupPosition; 
} 


@Override 
public boolean hasStableIds() { 
    return true; 
} 

@Override 
public boolean isChildSelectable(int groupPosition, int childPosition) { 
    return true; 
} 
} 
+0

任何logcat的錯誤? – Rahul

+0

發佈'R.layout.parent_row'文件的XML。 – chandil03

+0

parentrow膨脹問題是在子行 –

回答

0

我覺得onGroupClick方法是在你的代碼,如果點擊的處理應當返回true失蹤。

+0

我已經在代碼中加入了這個。 expandableListView.setOnGroupExpandListener(新ExpandableListView.OnGroupExpandListener(){ @Override 公共無效onGroupExpand(INT groupPosition){ Toast.makeText(getActivity(),parentObjectCollection.get(groupPosition)+ 「膨脹」,Toast.LENGTH_SHORT).show( ); } }); –

0

試試這個

expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { 
     @Override 
     public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { 
      Toast.makeText(MainActivity.this,headers.get(groupPosition)+"--"+headeritems.get(headers.get(groupPosition)).get(childPosition),Toast.LENGTH_SHORT).show(); 
      return false; 
     } 
    }); 

這裏指: - http://coderzpassion.com/tag/expandablelistview/