I have been implementing my android app with what I think is Passive MVP.
So for example in my view class I have a ListView.
ListView userListView;
and when an item is clicked, i simpley call a 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 that I am confused about is that a ListView requires an adapter.
So currently in my presenter I have this:
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 the right place to the adapter? The reason I ask is because I was recently looking to do some work with swing, and a similar issue arises, JLists need a ListModel which seems pretty similar. So for swing, where would should the ListModel reside?
I believe you've correctly categorized your adapter as a Presenter.
The Presenter IS the adapter.
The adapter serves as the middle-man between the View (ListView) and Model (your List of Users) and provides View representations of each of the items in the List via the adapter's getView method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With