开发者

Android ExpandableListView variable scope

i have a problem with ExpandableList开发者_JAVA百科View: in my app i use a ExpandableListView and i fill it with my adapter "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. 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. 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.

Hope that helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜