Where does the "adapter" correspond to MVP (passive view)?

I am using an Android app with what, in my opinion, is passive MVP.

So, for example, in my class class I have a ListView.

View

ListView userListView; 

and when the element is clicked, I just call the method on the presenter

 userListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mPresenter.onUserSelected(position); } }); 

The part I'm confused with is that ListView requires an adapter.

Presenter

So, my host currently has the following:

 private ArrayList<User> mUserList = new ArrayList<User>(); 

...

 adapter = new UserListAdapter(getContext(), mUserList); mView.setUserListAdapter(adapter); 

and when I want to change something, I do this:

 mUserList.add(user); adapter.notifyDataSetChanged(); 

Is this a suitable place for an adapter? The reason I'm asking for is because I recently looked for work with a swing, and a similar problem occurs, JLists need a ListModel that seems pretty similar. So, for the swing, where should the ListModel be?

+5
source share
2 answers

I believe that you correctly classified your adapter as a presenter.

A presenter is an adapter.

The adapter mediates between View (ListView) and Model (your list of users) and provides a representation of the views of each of the elements in the list through the adapter's getView method.

+5
source

In the MVP template, the presentation layer must contain all the platform dependencies. Check out this answer .

To handle adapter abstraction, you can use this .

0
source

Source: https://habr.com/ru/post/1206196/


All Articles