2012-09-20 62 views
3

我想過濾的ExpandableListView數據在Android中使用EditText,驗證adapter應該實現Filtering但不知道如何做到這一點的實現由於在過濾器上的數據缺乏知識。我的適配器的結構是:ExpandableListView的Android +過濾的EditText

public class ExpandableListAdapter extends 
     BaseExpandableListAdapter /*implements Filterable*/ { 

    private final Context myContext; 

    private String[] arrayTopics; 
    private String[][] arraySubTopics; 

    public PrimeirosSOSExpandableListAdapter(Context context) { 
     this.myContext = context; 
    } 

    public ExpandableListAdapter(Context context, 
      String[] arrayTopics, String[][] arraySubTopics) { 
     this.myContext = context; 
     this.arrayTopics = arrayTopics; 
     this.arraySubTopics = arraySubTopics; 

    } 

    public Object getChild(int groupPosition, int childPosition) { 
     return null; 
    } 

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

    public View getChildView(int groupPosition, int childPosition, 
      boolean isLastChild, View convertView, ViewGroup parent) { 

     if (convertView == null) { 
      LayoutInflater inflater = (LayoutInflater) myContext 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      convertView = inflater.inflate(R.layout.child_layout, 
        null); 
     } 

     TextView tv = (TextView) convertView.findViewById(R.id.tvChild); 
     tv.setText(arraySubTopics[groupPosition][childPosition]); 

     return convertView; 
    } 

    public int getChildrenCount(int groupPosition) { 
     return arraySubTopics[groupPosition].length; 
    } 

    public Object getGroup(int groupPosition) { 
     return null; 
    } 

    public int getGroupCount() { 
     return arrayTopics.length; 
    } 

    public long getGroupId(int groupPosition) { 
     return 0; 
    } 

    public View getGroupView(int groupPosition, boolean isExpanded, 
      View convertView, ViewGroup parent) { 

     if (convertView == null) { 
      LayoutInflater inflater = (LayoutInflater) myContext 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      convertView = inflater.inflate(R.layout.group_layout, 
        null); 
     } 

     TextView tv = (TextView) convertView.findViewById(R.id.tvGroup); 
     tv.setText(arrayTopics[groupPosition]); 

     return convertView; 
    } 

    public boolean hasStableIds() { 
     return false; 
    } 

    public boolean isChildSelectable(int groupPosition, int childPosition) { 
     return true; 
    } 
} 

回答

相關問題