Wednesday, 15 September 2010

android - Comunication through Adapter to notifyDataSetChanged() -



android - Comunication through Adapter to notifyDataSetChanged() -

i implemented situation described in image below:

the question is:

i have update gridview 2 when update gridview 1, how's best way this? update gridview 2 in adapter new volley request, maybe re-set adapter in fragment 2, utilize reference fragment 2 in adapter gridview 1 ?

details: gridview 1 updated notifydatasetchanged() on adapter performed after volley request adapter itself. can't utilize onresume() method of fragment 2 because it's not called due fragment it's showed @ same time of fragment 1.

any idea?

thanks.

a listener interface in java. can not create object of interface ("new" operator)

1) create interface

public interface onupdategridview2listener{ public void onupdate() //add kind of info want in parameters }

2) create fellow member of interface in adapter of gridview1 , phone call method

public gidviewadapter1 extends adapter{ private onupdategridview2listener mylistener; //your code @override public void notifydatasetchanged(){ //your code mylistener.onupdate(); } public void setonupdategridview2listener(onupdategridview2listener list){ this.mylistener = list; } }

3) implement interface in fragment , notify adapter

public fragmentgridview2 extends fragment implements onupdategridview2listener{ @override public void onupdate(){ //your code gridview2adapter.notifydatasetchanged(); } }

4) in activity, set listener when create fragmentgridview1

public youractivity{ //your code fragmentgridview1 fragment = new fragmentgridview1(); fragment.setonupdategridview2listener(getapplication()); }

android gridview android-fragments

No comments:

Post a Comment