强制ExpandableListView fastScroll迭代所有项而不是部分

Mar*_*ada 5 android expandablelistview expandablelistadapter fastscroll

我正在使用a ExpandableListViewBaseExpandableListAdapter我注意到启用fastScroll滚动会遍历各个部分或标题.如果它不是因为它不能正常工作那将是伟大的.将fastScroll通过与在上面滚动的只有一小部分的所有部分进行迭代,刚开始滚动,然后在通过滚动的第一季度的时候,所有的部分滚动到屏幕上,滚动什么也不做.

这是一个演示gif:

示范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>
Run Code Online (Sandbox Code Playgroud)

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;
  }
 }
}
Run Code Online (Sandbox Code Playgroud)