ZazoTazo

Mobile Adapter

Jul 31st, 2019
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.02 KB | None | 0 0
  1. package com.rcc2.www.listview;
  2.  
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.support.annotation.NonNull;
  7. import android.support.annotation.Nullable;
  8. import android.support.constraint.ConstraintLayout;
  9. import android.view.LayoutInflater;
  10. import android.view.View;
  11. import android.view.ViewGroup;
  12. import android.widget.ArrayAdapter;
  13. import android.widget.ImageView;
  14. import android.widget.TextView;
  15.  
  16. import java.util.ArrayList;
  17.  
  18. public class MobileAdapter extends ArrayAdapter<Mobile> {
  19.  
  20.     public MobileAdapter(@NonNull Context context, int resource, @NonNull ArrayList<Mobile> objects) {
  21.         super(context, resource, objects);
  22.     }
  23.  
  24.     @NonNull
  25.     @Override
  26.     public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) {
  27.         convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_design, parent,
  28.                 false);
  29.         TextView name = convertView.findViewById(R.id.mobileName);
  30.         TextView price = convertView.findViewById(R.id.mobilePrice);
  31.         ImageView image = convertView.findViewById(R.id.mobileImage);
  32.         ConstraintLayout layout = convertView.findViewById(R.id.layout);
  33.  
  34.         name.setText((getItem(position).getName()));
  35.         price.setText("" + getItem(position).getPrice());
  36.         image.setImageResource(getItem(position).getImage());
  37.  
  38.         layout.setOnClickListener(new View.OnClickListener() {
  39.             @Override
  40.             public void onClick(View view) {
  41.                 Intent intent = new Intent(getContext(), DetailsActivity.class);
  42.                 Bundle data = new Bundle();
  43.  
  44.                 data.putString("name", getItem(position).getName());
  45.                 data.putDouble("price", getItem(position).getPrice());
  46.                 data.putInt("image", getItem(position).getImage());
  47.                 intent.putExtras(data);
  48.  
  49.                 getContext().startActivity(intent);
  50.             }
  51.         });
  52.  
  53.         return convertView;
  54.     }
  55. }
Add Comment
Please, Sign In to add comment