Last active
August 21, 2017 07:02
-
-
Save SeongUgJung/31ce111065f79d1471fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends Activity implements MainPresenter.View { | |
MainPresenter mainPresenter; | |
RecyclerView.Adapter adapter; | |
@Override public void onCreate(Bundle savedInstance) { | |
RecyclerView rv = findViewById(R.id.lv); | |
adapter = new SampleAdapter(); | |
rv.setAdapter(adapter); | |
mainPresenter = new MainPresenter(this); | |
mainPresenter.initData(); | |
} | |
@Override public void addDatas(List<Data> datas) { | |
for (Data data : datas) { | |
adapter.add(data); | |
} | |
adapter.notifyDatasetChanged(); | |
} | |
private static class SampleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { | |
List<Data> datas; | |
SampleAdapter() { | |
datas = new ArrayLst<Data>(); | |
} | |
public void add(Data data) { | |
datas.add(data); | |
} | |
// ... | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainPresenter { | |
private MainPresenter.View view; | |
public MainPresenter(MainPresenter.View view ) { | |
this.view = view; | |
} | |
public void initData() { | |
List<Data> datas = new ArrayList<Data>(); | |
datas.add(new Data()); | |
datas.add(new Data()); | |
view.addDatas(datas); | |
} | |
public interface View { | |
void addDatas(List<Data> datas); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment