简体   繁体   中英

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". 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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