Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.rcc2.www.listview;
- import android.content.Context;
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.annotation.NonNull;
- import android.support.annotation.Nullable;
- import android.support.constraint.ConstraintLayout;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ArrayAdapter;
- import android.widget.ImageView;
- import android.widget.TextView;
- import java.util.ArrayList;
- public class MobileAdapter extends ArrayAdapter<Mobile> {
- public MobileAdapter(@NonNull Context context, int resource, @NonNull ArrayList<Mobile> objects) {
- super(context, resource, objects);
- }
- @NonNull
- @Override
- public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) {
- convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_design, parent,
- false);
- TextView name = convertView.findViewById(R.id.mobileName);
- TextView price = convertView.findViewById(R.id.mobilePrice);
- ImageView image = convertView.findViewById(R.id.mobileImage);
- ConstraintLayout layout = convertView.findViewById(R.id.layout);
- name.setText((getItem(position).getName()));
- price.setText("" + getItem(position).getPrice());
- image.setImageResource(getItem(position).getImage());
- layout.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent intent = new Intent(getContext(), DetailsActivity.class);
- Bundle data = new Bundle();
- data.putString("name", getItem(position).getName());
- data.putDouble("price", getItem(position).getPrice());
- data.putInt("image", getItem(position).getImage());
- intent.putExtras(data);
- getContext().startActivity(intent);
- }
- });
- return convertView;
- }
- }
Add Comment
Please, Sign In to add comment