Android 无法在ExpandableListView上快速滚动
我似乎无法使用我的Android 无法在ExpandableListView上快速滚动,android,expandablelistview,expandablelistadapter,Android,Expandablelistview,Expandablelistadapter,我似乎无法使用我的ExpandableListView快速滚动。更重要的是,我在适配器中实现的SectionIndexer方法从未真正被调用,我已经通过断点验证了这一点 以下是我的活动: private void onCreate(Bundle a) { ... setContentView(R.layout.mylayout); ... setListAdapter(myAdapter); getExpandableListView().set
ExpandableListView
快速滚动。更重要的是,我在适配器中实现的SectionIndexer
方法从未真正被调用,我已经通过断点验证了这一点
以下是我的活动:
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());
}
}
公共类适配器扩展了AbstractExpandableListAdapter
实现节索引器{
公共静态类TTDHolder{
文本视图标题;
}
公共静态类TTLHolder{
文本视图标题;
图像视图图标;
}
私有最终模式alphaMatch=Pattern.compile(“^[a-zA-Z]$”);
private final Pattern numbermach=Pattern.compile(“^\\d$”);
私人充气机;
公共适配器(上下文上下文、int-groupClosedView、int-groupExpandedView、int-childView、,
列出对象){
超级(上下文、groupClosedView、groupExpandedView、子视图、对象);
this.inflater=(LayoutInflater)context.getSystemService(context.LAYOUT\u inflater\u SERVICE);
}
公共视图getGroupView(int-groupPosition,布尔值isExpanded,
视图(视图、视图组父级){
TTDHolder支架;
if(convertView!=null){
holder=(TTDHolder)convertView.getTag();
}否则{
convertView=充气机。充气(R.layout.item,父项,false);
holder=新的TTDHolder();
holder.title=(TextView)convertView.findViewById(R.id.item_title);
convertView.setTag(支架);
}
holder.title.setText(this.getObjects().get(groupPosition.getKey().getName());
返回视图;
}
公共视图getChildView(int-groupPosition、int-childPosition、,
布尔值isLastChild、视图转换视图、视图组父级){
TTLHolder支架;
if(convertView!=null){
holder=(TTLHolder)convertView.getTag();
}否则{
convertView=充气机。充气(R.layout.item,父项,false);
保持架=新的TTLHolder();
holder.title=(TextView)convertView.findViewById(R.id.item_title);
holder.icon=(ImageView)convertView.findViewById(R.id.item_图标);
convertView.setTag(支架);
}
holder.title.setText(this.getObjects().get(groupPosition.getValue)()
.get(childPosition.getName());
返回视图;
}
公共对象[]getSections(){
返回“*1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ”。拆分(“”);
}
公共int getPositionForSection(int段){
for(条目:this.getObjects()){
if(entry.getKey().getName().substring(0,1)=getSections()[section])
返回此.getObjects().indexOf(条目);
}
返回0;
}
公共int getSectionForPosition(int位置){
List sections=Arrays.asList(getSections());
返回sections.indexOf(this.getObjects().get(position.getKey().getName().substring(0,1.toUpperCase());
}
}
然而,当我滚动时,我从来没有看到快速滚动器出现,也没有实际调用过
SectionIndexer
方法 事实证明,您的适配器中需要有最少数量的项目才能显示快速查看滚动条。事实证明,您的适配器中需要有最少数量的项目才能显示快速查看滚动条