Guest User

Untitled

a guest
May 27th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity implements MainContract.View, Button.OnClickListener {
  2.  
  3. private MainContract.Presenter mainPresenter;
  4.  
  5. private RecyclerView recyclerViewFriend;
  6. private EditText txtInputName, txtInputPhone;
  7. private Button btnSaveFriend;
  8. private RecyclerViewFriendAdapter recyclerViewFriendAdapter;
  9.  
  10. @Override
  11. protected void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.activity_main);
  14. mainPresenter = new MainPresenterImpl(this);
  15. initViews();
  16. }
  17.  
  18. private void initViews(){
  19. txtInputName = findViewById(R.id.txtInputName);
  20. txtInputPhone = findViewById(R.id.txtInputPhone);
  21. btnSaveFriend = findViewById(R.id.btnSaveFriend);
  22. btnSaveFriend.setOnClickListener(this);
  23. recyclerViewFriend = findViewById(R.id.recyclerViewFriend);
  24. }
  25.  
  26. @Override
  27. public void showFriend(List<Friend> friendList) {
  28. recyclerViewFriendAdapter = new RecyclerViewFriendAdapter(this, friendList);
  29. recyclerViewFriend.setLayoutManager(new LinearLayoutManager(this));
  30. recyclerViewFriend.setAdapter(recyclerViewFriendAdapter);
  31. recyclerViewFriendAdapter.notifyDataSetChanged();
  32. }
  33.  
  34. @Override
  35. public void clearInput() {
  36. txtInputName.setText("");
  37. txtInputPhone.setText("");
  38. txtInputName.requestFocus();
  39. }
  40.  
  41. @Override
  42. public void onClick(View v) {
  43. switch (v.getId()){
  44. case R.id.btnSaveFriend:
  45. mainPresenter.saveFriend(new Friend(txtInputName.getText().toString(), txtInputPhone.getText().toString()));
  46. break;
  47. }
  48. }
  49. }
Add Comment
Please, Sign In to add comment