Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity implements MainContract.View, Button.OnClickListener {
- private MainContract.Presenter mainPresenter;
- private RecyclerView recyclerViewFriend;
- private EditText txtInputName, txtInputPhone;
- private Button btnSaveFriend;
- private RecyclerViewFriendAdapter recyclerViewFriendAdapter;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- mainPresenter = new MainPresenterImpl(this);
- initViews();
- }
- private void initViews(){
- txtInputName = findViewById(R.id.txtInputName);
- txtInputPhone = findViewById(R.id.txtInputPhone);
- btnSaveFriend = findViewById(R.id.btnSaveFriend);
- btnSaveFriend.setOnClickListener(this);
- recyclerViewFriend = findViewById(R.id.recyclerViewFriend);
- }
- @Override
- public void showFriend(List<Friend> friendList) {
- recyclerViewFriendAdapter = new RecyclerViewFriendAdapter(this, friendList);
- recyclerViewFriend.setLayoutManager(new LinearLayoutManager(this));
- recyclerViewFriend.setAdapter(recyclerViewFriendAdapter);
- recyclerViewFriendAdapter.notifyDataSetChanged();
- }
- @Override
- public void clearInput() {
- txtInputName.setText("");
- txtInputPhone.setText("");
- txtInputName.requestFocus();
- }
- @Override
- public void onClick(View v) {
- switch (v.getId()){
- case R.id.btnSaveFriend:
- mainPresenter.saveFriend(new Friend(txtInputName.getText().toString(), txtInputPhone.getText().toString()));
- break;
- }
- }
- }
Add Comment
Please, Sign In to add comment