我可以找到基于文本的可扩展列表视图项吗

发布于 2024-11-09 19:44:38 字数 251 浏览 5 评论 0原文

这个 sudo 代码可以吗?

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

我不知道如何编码。如果您需要任何说明,请告诉我。

Is this sudo code possible?

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

I cannot figure out how to code this. Let me know if you need any clarification.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月亮坠入山谷 2024-11-16 19:44:38

我在我的应用程序中做了类似的事情。我浏览了 Android Developer 网站上的 ExpandableListView 小部件。它似乎没有任何 get 方法可以让您比较 ExpandableListView 中项目的字符串值。

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

换句话说,get 方法将返回值"i"。使用 myStringArray[i].equals("This string") 比较字符串值。

I've done something similar to this with my app. I've looked through the ExpandableListView widget on the Android Developer site. It doesn't seem to have any get methods that will allow you to compare the string value of the items in your ExpandableListView.

What you'll have to do is create your own array of strings that hold the string values you want. Then use the get method of ExpandableListView that returns the position of the item selected and compare it to your string array.

In other words, the get method will return value "i". Use myStringArray[i].equals("This string") to compare the string values.

蘸点软妹酱 2024-11-16 19:44:38

这似乎是 Adapter 类中 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;       
}

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

It seems a task for getChildView in your Adapter class.

I've done the same for groups in my 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;       
}

Warning! This code is not optimized, it inflates every item, this is expensive. In my case I didn't worry because my ExpandableListView had a few items

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文