Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DataCustomer {
- private int image;
- private String name;
- private int phonenumber;
- public DataCustomer(String name, int phonenumber, int image) {
- this.image = image;
- this.name = name;
- this.phonenumber = phonenumber;
- }
- public int getImage() {
- return image;
- }
- public void setImage(int image) {
- this.image = image;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public int getPhonenumber() {
- return phonenumber;
- }
- public void setPhonenumber(int phonenumber) {
- this.phonenumber = phonenumber;
- }}
- public class CustomerAdapter extends RecyclerView.Adapter<CustomerAdapter.ViewHolder> {
- private ArrayList<DataCustomer> dataCustomers;
- private Context context;
- public CustomerAdapter(ArrayList<DataCustomer> dataCustomers, Context context) {
- this.dataCustomers = dataCustomers;
- this.context = context;
- }
- @NonNull
- @Override
- public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
- LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
- View itemView = layoutInflater.inflate(R.layout.item_customer,parent,false);
- return new ViewHolder(itemView);
- }
- @Override
- public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
- holder.customer_name.setText(dataCustomers.get(position).getName());
- holder.customer_phone.setText(dataCustomers.get(position).getPhonenumber());
- holder.customer_image.setImageResource(dataCustomers.get(position).getImage());
- }
- @Override
- public int getItemCount() {
- return dataCustomers.size();
- }
- public class ViewHolder extends RecyclerView.ViewHolder{
- TextView customer_name;
- TextView customer_phone;
- ImageView customer_image;
- public ViewHolder(View itemView){
- super(itemView);
- customer_name = (TextView)itemView.findViewById(R.id.customer_name);
- customer_phone = (TextView) itemView.findViewById(R.id.customer_phone);
- customer_image = (ImageView)itemView.findViewById(R.id.customer_image);
- }
- }}
- public class CustomerInfoActivity extends AppCompatActivity {
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.customer_info);
- initView();
- }
- public void initView(){
- RecyclerView recyclerView = (RecyclerView)findViewById(R.id.customer_items);
- recyclerView.setHasFixedSize(true);
- LinearLayoutManager layoutManager = new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false);
- recyclerView.setLayoutManager(layoutManager);
- ArrayList<DataCustomer> arrayList = new ArrayList<>();
- arrayList.add(new DataCustomer("A",12,R.drawable.A));
- arrayList.add(new DataCustomer("B",34,R.drawable.B));
- arrayList.add(new DataCustomer("C",56,R.drawable.C));
- arrayList.add(new DataCustomer("D",78,R.drawable.D));
- CustomerAdapter customerAdapter = new CustomerAdapter(arrayList, getApplicationContext());
- recyclerView.setAdapter(customerAdapter);
- }}
- public class MainActivity extends AppCompatActivity {
- private static EditText username;
- private static EditText password;
- private static CheckBox rememberpassword;
- private static Button loginbutton;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- loginButton();
- }
- public void loginButton(){
- username = (EditText)findViewById(R.id.editText_username);
- password = (EditText)findViewById(R.id.editText_password);
- rememberpassword = (CheckBox)findViewById(R.id.checkBox_rememberpassword);
- loginbutton = (Button)findViewById(R.id.button_login);
- loginbutton.setOnClickListener(
- new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if(username.getText().toString().equals("user") &&
- password.getText().toString().equals("pass") ) {
- Intent intent = new Intent("com.assignment.assignment2_v2.CustomerInfoActivity");
- startActivity(intent);
- }
- }
- }
- );
- }
- }
- Intent intent = new Intent(MainActivity.this, CustomerInfoActivity.class);
- startActivity(intent);
Add Comment
Please, Sign In to add comment