Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我能否找到基于文本的expandablelistview项_Java_Android_Expandablelistview - Fatal编程技术网

Java 我能否找到基于文本的expandablelistview项

Java 我能否找到基于文本的expandablelistview项,java,android,expandablelistview,Java,Android,Expandablelistview,这个sudo代码可能吗 for (all children in my custom expandable list) { if (childItemText.equals("This string") { viewWithTextIWant.setBackgroundResource(R.color.blue) } } 我不知道该如何编写代码。如果您需要任何澄清,请告诉我。我的应用程序也做了类似的事情。我已经浏览了网站上的ExpandableList

这个sudo代码可能吗

for (all children in my custom expandable list) {
     if (childItemText.equals("This string") {
           viewWithTextIWant.setBackgroundResource(R.color.blue)
     }
}

我不知道该如何编写代码。如果您需要任何澄清,请告诉我。

我的应用程序也做了类似的事情。我已经浏览了网站上的ExpandableListView小部件。它似乎没有任何get方法允许您比较
ExpandableListView
中项目的字符串值

您需要做的是创建您自己的字符串数组,其中包含您想要的字符串值。然后使用
ExpandableListView
的get方法返回所选项目的位置,并将其与字符串数组进行比较


换句话说,get方法将返回值
“i”
。使用mystringaray[i].equals(“此字符串”)比较字符串值。

在适配器类中,getChildView似乎有一项任务

我已经对ExpandableListView中的组执行了相同的操作:

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    String groupText = (String) ((Map<String,?>) mGroupData.get(groupPosition)).get(KEY);
    View v = groupText.startsWith(SEARCH_TERM) ?
                        mInflater.inflate(R.layout.layout_1, null) : mInflater.inflate(R.layout.layout_2, null); 
    TextView tv = (TextView) v.findViewById(R.id.mytext);
    tv.setText(groupText);
    return v;       
}
@覆盖
公共视图getGroupView(int groupPosition、布尔isExpanded、视图convertView、视图组父级){
String groupText=(String)((Map)mGroupData.get(groupPosition)).get(KEY);
查看v=groupText.startsWith(搜索词)?
充气(R.layout.layout_1,空):充气(R.layout.layout_2,空);
TextView电视=(TextView)v.findviewbyd(R.id.mytext);
tv.setText(groupText);
返回v;
}

警告!这个代码没有经过优化,它会使每一件物品膨胀,这很昂贵。就我而言,我并不担心,因为我的ExpandableListView有几个项目

@yellavon:ExpandedListView有几个“onclick”监听器可以使用。可能就是你要找的那个。您可以将代码放入该侦听器的
onChildClick
函数中。