gpt4 book ai didi

android - ExpandableListView 安卓+过滤EditText

转载 作者:太空狗 更新时间:2023-10-29 14:26:02 25 4
gpt4 key购买 nike

我想在 android 中使用 EditText 过滤 ExpandableListView 中的数据,验证 adapter 应该实现 Filtering 但不知道如何完成此实现,因为缺乏有关过滤数据的知识。我的适配器的结构是:

    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;
}
}

最佳答案

我自己对 Android 的这一部分了解不多,因为我是新手,但我在研究另一个问题时确实看到了一些关于 CursorTreeAdapter 的东西。它内置了一些方法来处理过滤。这是关于它的 Android API 信息。 CursorTreeAdapter 可以与 ExpandableListView 一起使用。

http://developer.android.com/reference/android/widget/CursorTreeAdapter.html

关于android - ExpandableListView 安卓+过滤EditText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12522509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com