2011-03-04 155 views
0

我似乎无法使用我的ExpandableListView快速滚动。更重要的是,我在适配器中实现的SectionIndexer方法从来没有被实际调用,并且我通过断点验证了这一点。无法快速滚动ExpandableListView

这里是我的活动:

private void onCreate(Bundle a) { 
    ... 
    setContentView(R.layout.mylayout); 
    ... 
    setListAdapter(myAdapter); 
    getExpandableListView().setFastScrollEnabled(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"> 

    <ExpandableListView android:id="@+id/android:list" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fastScrollEnabled="true"/> 

    <TextView android:id="@+id/android:empty" 
      android:text="EMPTY! DOOM!" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 
</LinearLayout> 

这里是我的适配器,它的工作原理是方式:

public class Adapter extends AbstractExpandableListAdapter<TTD, TTL> 
     implements SectionIndexer { 

    public static class TTDHolder { 
     TextView title; 
    } 

    public static class TTLHolder { 
     TextView title; 
     ImageView icon; 
    } 

    private final Pattern alphaMatch = Pattern.compile("^[a-zA-Z]$"); 

    private final Pattern numberMatch = Pattern.compile("^\\d$"); 

    private LayoutInflater inflater; 

    public Adapter(Context context, int groupClosedView, int groupExpandedView, int childView, 
      List<Entry<TTD, List<TTL>>> objects) { 
     super(context, groupClosedView, groupExpandedView, childView, objects); 
     this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    } 

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

     if (convertView != null) { 
      holder = (TTDHolder)convertView.getTag(); 
     } else { 
      convertView = inflater.inflate(R.layout.item, parent, false); 

      holder = new TTDHolder(); 
      holder.title = (TextView) convertView.findViewById(R.id.item_title); 

      convertView.setTag(holder); 
     } 

     holder.title.setText(this.getObjects().get(groupPosition).getKey().getName()); 

     return convertView; 
    } 

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

     if (convertView != null) { 
      holder = (TTLHolder) convertView.getTag(); 
     } else { 
      convertView = inflater.inflate(R.layout.item, parent, false); 

      holder = new TTLHolder(); 
      holder.title = (TextView) convertView.findViewById(R.id.item_title); 
      holder.icon = (ImageView) convertView.findViewById(R.id.item_icon); 

      convertView.setTag(holder); 
     } 

     holder.title.setText(this.getObjects().get(groupPosition).getValue() 
       .get(childPosition).getName()); 

     return convertView; 
    } 

    public Object[] getSections() { 
     return "*1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""); 
    } 

    public int getPositionForSection(int section) { 
     for (Entry<TTD, List<TTL>> entry : this.getObjects()) { 
      if (entry.getKey().getName().substring(0, 1) == getSections()[section]) 
       return this.getObjects().indexOf(entry); 
     } 

     return 0; 
    } 

    public int getSectionForPosition(int position) { 
     List<Object> sections = Arrays.asList(getSections()); 
     return sections.indexOf(this.getObjects().get(position).getKey().getName().substring(0, 1).toUpperCase()); 
    } 
} 

然而,当我滚动,我从来没有看到快速滚动显示,也没有实际调用的方法。

回答

3

事实证明,您需要在适配器中拥有最少数量的项目才能显示快速浏览滚动条。