Reputation: 3904
In MVP pattern, action from user must deliver to presenter
so in listView when user click on item I want send this action to presenter
what is the best case for communicating adapter with Activity/Fragment?
and I appreciate it if you explain pros and cond of each one.
Upvotes: 1
Views: 1470
Reputation: 2372
The communication between View
& Presenter
should be through an interface
.
Both Presenter
and Activity
(view) have their own interface
.
Here's a good example of MVP interfaces
A good/brief explanation of MVP
Edit
Adapter
& Activity
/Fragment
.First point - in my personal view Adapter
& Activity
/Fragment
are all subsections of View
in the MVP architecture.
The Activity
will hold reference to the Adapter
The Activity
(via the Presenter
) can mainpualte the data in the adapter by the usual means i.e. changing the underlying data object and calling notifyDataSetChanged
.
As for the Adapter
sending requests back to the Activity
i.e. View.OnClickListener
this can be done via callbacks that are sent when the Adapter
is first initialised (i.e. created using the new
keyword)
Upvotes: 1
Reputation: 14053
Depending on your scenario u can adopt given below methods
Try using an interface
https://stackoverflow.com/a/16443645/4247543
if the above method is not helping then try using EventBus
please follow below link to know more of Event Bus
https://github.com/greenrobot/EventBus
http://gunhansancar.com/ease-communication-between-activities-fragments-services/
BroadcastReceiver as mentioned could also help for enabling communication.
https://stackoverflow.com/a/10084754/4247543
You can use observers
https://stackoverflow.com/a/30964385/4247543
Hopes it helps.
Upvotes: 0
Reputation: 147
You can always use callbacks for listening clicks. You should implement is using interfaces.
Upvotes: 0