开发者

Do ListAdapters need to be released, or is that handled automatically?

开发者 https://www.devze.com 2023-02-04 11:14 出处:网络
When a user selects an item in a ListView, I display a new list based on their selection using a new ListAdapter in the same activity.Do I need to release the previous ListAdapter, or will the ListVie

When a user selects an item in a ListView, I display a new list based on their selection using a new ListAdapter in the same activity. Do I need to release the previous ListAdapter, or will the ListView handle that automatically?

I'm allocating ListAdapters like thi开发者_JAVA技巧s:

            ListAdapter adapter=new SimpleCursorAdapter(this,
                R.layout.row, tempCursor,
                new String[] {"name"},
                new int[] {R.id.name});

        setListAdapter(adapter);


ListView will take care of releasing the previous adapter automagically. You do not need to worry about it.


I have a similar situation in an Android activity where the activity loads a new ListAdapter based on selected checkboxes in the activity. I simply declare a new ListAdapter and set it to be the current one and it works, I do not need to "release" or do anything with the existing one.

public void onClick(View v)
{
    populateCheckedMembers();
    adapter = new MemberAdapter(this, R.layout.members_row, checkedMembers);
    setListAdapter(adapter);
}
0

精彩评论

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