Alan Lai
Alan Lai

Reputation: 1104

how to reset listview?

I have a list view in this activity

First, i will display list view with this

adapter = new CustomAdapter_LatestNews(this, title, category, date,
            imagepath);     

lv.addFooterView(constant.AdMob());
lv.setAdapter(adapter);

I am using custom adapter which extend base adapter.

public View getView(int position, View convertView, ViewGroup parent)

In this activity, i have a refresh button which was update data and call back same activity.

startActivity(new Intent(Main_AllLatestNews.this, Main_AllLatestNews.class));
finish(); 

It seem like the getview is reusing the data?

Before press refresh button

result > image 0 0 0 0 1 0 1 0 0 0 correct display (no matter how i scroll)

After press refresh button

result > image 1 1 1 1 1 1 1 1 1 1 incorrect display (scroll will cause this)

How to solve this problem?

Upvotes: 1

Views: 7727

Answers (2)

Seadon Francis Pinto
Seadon Francis Pinto

Reputation: 329

You Could try & it worked for me:

Initialization of the list view and adapter:

listView = (ListView) findViewById(R.id.list_view);
adapter = new MessageAdapter(this);
listView.setAdapter(adapter);

Reset the list and the adapter array:

listView.removeAllViewsInLayout();
listMessages.clear();

Upvotes: 2

Tal Kanel
Tal Kanel

Reputation: 10785

the right way to refresh list view is not by restarting the activity.

instead - after refreshing the logic list /or the data the adapter working with, all you need to do is to call:

adapter.notifyDataSetChanged();

Upvotes: 0

Related Questions