我正在使用ExpandableListView
andBaseExpandableListAdapter
我注意到启用fastScroll
滚动会遍历部分或标题。如果不是因为它不能正常工作,那就太好了。fastScroll
遍历所有部分,顶部只有一小部分滚动,刚刚开始滚动,然后当滚动的第一季度通过并且所有部分都滚动到屏幕上时,滚动什么也不做。
这是一个演示gif:
我已经检查了这个旧帖子android fastScroll 只涵盖了列表的一部分,但对我不起作用。
任何人都知道此错误的另一种解决方法或知道如何强制ExpandableListView
fastScroll
遍历所有项目而不是部分?
这是示例代码,如果它对您有用。
activity_main.xml
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ExpandableListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:fastScrollEnabled="true"
android:layout_height="match_parent"></ExpandableListView>
</FrameLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
private ExpandableListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = findViewById(R.id.listview);
ExpandableAdapter adapter = new ExpandableAdapter(this, getItems());
listView.setAdapter(adapter);
}
private Map<String, List<String>> getItems() {
Map<String, List<String>> items = new LinkedHashMap<>();
// Loops to create stub items
return items;
}
private static class ExpandableAdapter extends BaseExpandableListAdapter {
private final Context context;
private ArrayList<String> sections;
private Map<String, List<String>> items;
public ExpandableAdapter(Context context, Map<String, List<String>> items) {
this.context = context;
this.items = items;
this.sections = new ArrayList<>(items.keySet());
}
@Override
public int getGroupCount() {
return sections.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return items.get(sections.get(groupPosition)).size();
}
@Override
public String getGroup(int groupPosition) {
return sections.get(groupPosition);
}
@Override
public String getChild(int groupPosition, int childPosition) {
return items.get(getGroup(groupPosition)).get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return 0;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return 0;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean b, View view, ViewGroup viewGroup) {
// No ViewHolder pattern because of testing purposes
view = View.inflate(context, R.layout.row, null);
TextView tv = view.findViewById(R.id.text);
tv.setText(getGroup(groupPosition));
return view;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean b, View view, ViewGroup viewGroup) {
// No ViewHolder pattern because of testing purposes
view = View.inflate(context, R.layout.row, null);
TextView tv = view.findViewById(R.id.text);
tv.setText(getChild(groupPosition, childPosition));
return view;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
}
}