Search code examples
javaandroidlistviewnotifydatasetchanged

Update Listview visible view (row) from another activity


enter image description here Hi there. H have a list view that populated by MyCustomAdapter. in my Custom Adapter, I retrieve data from server by json and keep them in ArrayList<HashMap<String, String>>

MyCustomAdapter constructor is like this:

public MyCustomAdapter(Activity a, ArrayList<HashMap<String, String>> d){
        mActivity   = a;
        mData       = d;
        mInflater   = (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

and in my getView I retrieve data From mData and set them to views like Title, Description and so on that you can see in image.

I want update my listview data in back time when user goes to edit activity and edit some data there. How can do that?

In Google+ app when you read a post and like that on post activity, when you back to list of all posts, that post like button was updated!! I want something like this

thanks for any help :)


Solution

  • Since you are using an ArrayList<HashMap<String, String>> an not a cursor/contentprovider your adapter won't be automatically notified automatically by changes on the underlying data.

    One way is to use something like Otto (http://square.github.io/otto/) or any event bus to pass events, to notify your activities of some changes on the underlying data.

    Your first activity should subscribe to the data update event, and then on your second activity you should send this activity together with the new data