Guest User

Untitled

a guest
Apr 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. public class DataCustomer {
  2. private int image;
  3. private String name;
  4. private int phonenumber;
  5.  
  6. public DataCustomer(String name, int phonenumber, int image) {
  7. this.image = image;
  8. this.name = name;
  9. this.phonenumber = phonenumber;
  10. }
  11.  
  12. public int getImage() {
  13. return image;
  14. }
  15.  
  16. public void setImage(int image) {
  17. this.image = image;
  18. }
  19.  
  20. public String getName() {
  21. return name;
  22. }
  23.  
  24. public void setName(String name) {
  25. this.name = name;
  26. }
  27.  
  28. public int getPhonenumber() {
  29. return phonenumber;
  30. }
  31.  
  32. public void setPhonenumber(int phonenumber) {
  33. this.phonenumber = phonenumber;
  34. }}
  35.  
  36. public class CustomerAdapter extends RecyclerView.Adapter<CustomerAdapter.ViewHolder> {
  37. private ArrayList<DataCustomer> dataCustomers;
  38. private Context context;
  39.  
  40. public CustomerAdapter(ArrayList<DataCustomer> dataCustomers, Context context) {
  41. this.dataCustomers = dataCustomers;
  42. this.context = context;
  43. }
  44.  
  45. @NonNull
  46. @Override
  47. public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
  48. LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
  49. View itemView = layoutInflater.inflate(R.layout.item_customer,parent,false);
  50. return new ViewHolder(itemView);
  51. }
  52.  
  53. @Override
  54. public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
  55. holder.customer_name.setText(dataCustomers.get(position).getName());
  56. holder.customer_phone.setText(dataCustomers.get(position).getPhonenumber());
  57. holder.customer_image.setImageResource(dataCustomers.get(position).getImage());
  58.  
  59. }
  60.  
  61. @Override
  62. public int getItemCount() {
  63. return dataCustomers.size();
  64. }
  65.  
  66. public class ViewHolder extends RecyclerView.ViewHolder{
  67. TextView customer_name;
  68. TextView customer_phone;
  69. ImageView customer_image;
  70.  
  71. public ViewHolder(View itemView){
  72. super(itemView);
  73. customer_name = (TextView)itemView.findViewById(R.id.customer_name);
  74. customer_phone = (TextView) itemView.findViewById(R.id.customer_phone);
  75. customer_image = (ImageView)itemView.findViewById(R.id.customer_image);
  76.  
  77. }
  78. }}
  79.  
  80. public class CustomerInfoActivity extends AppCompatActivity {
  81.  
  82. protected void onCreate(Bundle savedInstanceState) {
  83. super.onCreate(savedInstanceState);
  84. setContentView(R.layout.customer_info);
  85. initView();
  86. }
  87. public void initView(){
  88. RecyclerView recyclerView = (RecyclerView)findViewById(R.id.customer_items);
  89. recyclerView.setHasFixedSize(true);
  90.  
  91. LinearLayoutManager layoutManager = new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false);
  92. recyclerView.setLayoutManager(layoutManager);
  93. ArrayList<DataCustomer> arrayList = new ArrayList<>();
  94.  
  95. arrayList.add(new DataCustomer("A",12,R.drawable.A));
  96. arrayList.add(new DataCustomer("B",34,R.drawable.B));
  97. arrayList.add(new DataCustomer("C",56,R.drawable.C));
  98. arrayList.add(new DataCustomer("D",78,R.drawable.D));
  99.  
  100. CustomerAdapter customerAdapter = new CustomerAdapter(arrayList, getApplicationContext());
  101. recyclerView.setAdapter(customerAdapter);
  102. }}
  103.  
  104. public class MainActivity extends AppCompatActivity {
  105. private static EditText username;
  106. private static EditText password;
  107. private static CheckBox rememberpassword;
  108. private static Button loginbutton;
  109. @Override
  110. protected void onCreate(Bundle savedInstanceState) {
  111. super.onCreate(savedInstanceState);
  112. setContentView(R.layout.activity_main);
  113. loginButton();
  114.  
  115. }
  116. public void loginButton(){
  117. username = (EditText)findViewById(R.id.editText_username);
  118. password = (EditText)findViewById(R.id.editText_password);
  119. rememberpassword = (CheckBox)findViewById(R.id.checkBox_rememberpassword);
  120. loginbutton = (Button)findViewById(R.id.button_login);
  121.  
  122. loginbutton.setOnClickListener(
  123. new View.OnClickListener() {
  124. @Override
  125. public void onClick(View v) {
  126. if(username.getText().toString().equals("user") &&
  127. password.getText().toString().equals("pass") ) {
  128.  
  129. Intent intent = new Intent("com.assignment.assignment2_v2.CustomerInfoActivity");
  130. startActivity(intent);
  131. }
  132. }
  133. }
  134. );
  135. }
  136. }
  137.  
  138. Intent intent = new Intent(MainActivity.this, CustomerInfoActivity.class);
  139. startActivity(intent);
Add Comment
Please, Sign In to add comment