开发者

Refresh ListView when returned to activity on android

开发者 https://www.devze.com 2023-02-03 18:40 出处:网络
I am currently developing an android app. The app has 2 activities. Activity 1 is a ListActivity. ListActivity calls a standard Activ开发者_StackOverflow社区ity. When the 2nd activity is finished, I u

I am currently developing an android app. The app has 2 activities. Activity 1 is a ListActivity. ListActivity calls a standard Activ开发者_StackOverflow社区ity. When the 2nd activity is finished, I use the finish() method to close the activitity which returns to the ListActivity. I need the ListActivity to now refresh with the new dat


You should just call notifyDataSetChanged() on your adapter when you return back to your activity.

The API states:

void notifyDataSetChanged()

Notifies the attached View that the underlying data has been changed and it should refresh itself.


Have you packaged the data into and intent? For that matter did you startActivityForResult()? If so the you would take the data out of the intent by overriding the onActivityResult(...) method and add the data to what ever you need to do. Then like sahhhm said notifyDataSetChanged().

~Aedon


You need reload the info in the ListView...

@Override
protected void onResume() {
    super.onResume();

    mAdapter= new mYCustomAdapter(mActivity.this, valuesReloaded);
            mList.setAdapter(mAdapter); 

           mAdapter.myMethodThatNotifyChange();  

}

where: valuesReloaded is the new Array with the new Values. mAdapter is a Custom Adapter myMethodThatNotifyChange is a method in the Class MyCustomAdapter where you must call notifyDataSetChanged() , ( in a custom adapter can only call from the class adapter)

class myCustomAdapter extends BaseAdapter{
...
...
myMethodThatNotifyChange{
notifyDataSetChanged();
}
...
...
}

Or finish the actual activity, and reload with a new intent

    @Override
    protected void onResume() {
        super.onResume();

Intent mIntet = new Intent(mlistViewPersons.this , mlistViewPersons.class)
startActivity(mIntent);
finish();

}
0

精彩评论

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