简体   繁体   English

Android ExpandableListView变量范围

[英]Android ExpandableListView variable scope

i have a problem with ExpandableListView: in my app i use a ExpandableListView and i fill it with my adapter "class MyExpandableListAdapter extends BaseExpandableListAdapter". 我在ExpandableListView中遇到问题:在我的应用中,我使用ExpandableListView,并用适配器"class MyExpandableListAdapter extends BaseExpandableListAdapter".填充它"class MyExpandableListAdapter extends BaseExpandableListAdapter". In method 在方法中

   public View getChildView(int groupPosition, int childPosition, boolean isLastChild, view convertView, ViewGroup parent) {
        if (groupPosition == 0) {
            SearchView search = new SearchView(ApplicationPlaceActivity.this);
            return search;
        } else if (groupPosition == 1) {
            MyUpdates myUp = new MyUpdates(ApplicationPlaceActivity.this);
            return myUp;
        }
    }

This code works fine, but it's not good for me because every time i create a new instance of SearchView and MyUpdate. 这段代码可以正常工作,但对我来说却不好,因为每次我创建SearchView和MyUpdate的新实例时。 I make "SearchView search" and "MyUpdates myUp" as global variables but this creates some issues: after a while the layout doesn't respond on touch event, or better it responds on next touch event. 我将"SearchView search""MyUpdates myUp"为全局变量,但这会产生一些问题:一段时间后,布局在触摸事件上不响应,或者更好的是在下一次触摸事件上响应。 so i came back with the original code posted here, but this it's no good for me. 所以我回到了这里发布的原始代码,但这对我没有好处。 any suggestion? 有什么建议吗? thanks 谢谢

Try to find a way to not create a new view each time. 尝试找到一种不每次都创建新视图的方法。 I don't really understand why you would need to. 我不太了解您为什么需要这么做。 Also why would you need to store it globally? 还有为什么您需要将其全局存储? You should consider only storing an identifier such as the position or the id. 您应该考虑只存储一个标识符,例如位置或ID。

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM