自定义ExpendableListView适配器不起作用

时间:2019-10-09 10:42:32

标签: android

不是Expandablelistview中的子值。呼叫

Products_With_ProfileSubModel item = (Products_With_ProfileSubModel) (expandableListDetail.get(expandableListTitle.get(listPosition)).get(expandedListPosition));
public class CustomExpandableListAdapter extends BaseExpandableListAdapter implements Filterable {

    private Context context;
    private ArrayList<Products_With_ProfileModel> expandableListTitle;

    private HashMap<Products_With_ProfileModel, List<Products_With_ProfileSubModel>> expandableListDetail;
    private int layoutResourceId;
    private int layoutsubResourceId;

    public CustomExpandableListAdapter(Context context, int layoutResourceId, ArrayList<Products_With_ProfileModel> expandableListTitle, int layoutsubResourceId, HashMap<Products_With_ProfileModel, List<Products_With_ProfileSubModel>> expandableListDetail) {
        this.context = context;
        this.layoutResourceId = layoutResourceId;
        this.expandableListTitle = expandableListTitle;
        this.layoutsubResourceId = layoutsubResourceId;
        this.expandableListDetail = expandableListDetail;
    }

    @Override
    public Object getChild(int listPosition, int expandedListPosition) {
        return this.expandableListDetail.get(this.expandableListTitle.get(listPosition)).get(expandedListPosition);
    }

    @Override
    public long getChildId(int listPosition, int expandedListPosition) {
        return expandedListPosition;
    }

    @Override
    public View getChildView(int listPosition, final int expandedListPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        View row = convertView;
        ViewHolder2 holder;

        if (row == null) {
            LayoutInflater inflater = ((Activity) context).getLayoutInflater();
            row = inflater.inflate(layoutsubResourceId, parent, false);
            holder = new ViewHolder2();
            holder.user_id = (TextView) row.findViewById(R.id.profile_product_id1);
            holder.name = (TextView) row.findViewById(R.id.profile_product_desc1);
            holder.image = (ImageView) row.findViewById(R.id.profile_product_img);

            row.setTag(holder);

        } else {
            holder = (ViewHolder2) row.getTag();
        }
        Products_With_ProfileSubModel item = (Products_With_ProfileSubModel) (expandableListDetail.get(expandableListTitle.get(listPosition)).get(expandedListPosition));
        assert item.getExpandableListDetail() != null;
        holder.user_id.setText(item.getId());
        holder.name.setText(item.getName());
        holder.image.setImageDrawable(null);
        Picasso.get()
                .load(item.getImage())
                .fit().centerCrop()
                .into(holder.image);

        return row;
    }
    class ViewHolder2 {
        TextView user_id, name;
        ImageView image;
    }

    class ViewHolder {
        TextView user_id, name, shop_name, location, min_qty, deivery_date, cust_repeat;
        ImageView image;
        CircleImageView pro_img;
        LinearLayout profile_lay;
    }

    @Override
    public int getChildrenCount(int listPosition) {
        return this.expandableListDetail.get(this.expandableListTitle.get(listPosition)).size();
    }

    @Override
    public Object getGroup(int listPosition) {
        return this.expandableListTitle.get(listPosition);
    }

    @Override
    public int getGroupCount() {
        return this.expandableListTitle.size();
    }

    @Override
    public long getGroupId(int listPosition) {
        return listPosition;
    }

    @Override
    public View getGroupView(int listPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        View row = convertView;
        ViewHolder holder;

        if (row == null) {
            LayoutInflater inflater = ((Activity) context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
            holder = new ViewHolder();
            holder.user_id = (TextView) row.findViewById(R.id.profile_product_user_id);
            holder.name = (TextView) row.findViewById(R.id.profile_product_name);
            holder.shop_name = (TextView) row.findViewById(R.id.profile_product_shop_name);
            holder.location = (TextView) row.findViewById(R.id.profile_product_location);
            holder.image = (ImageView) row.findViewById(R.id.profile_product_img);
            holder.min_qty = (TextView) row.findViewById(R.id.min_qty);
            holder.deivery_date = (TextView) row.findViewById(R.id.deivery_date);
            holder.pro_img = (CircleImageView) row.findViewById(R.id.pro_img);
            holder.cust_repeat = (TextView) row.findViewById(R.id.cust_repeat);
            holder.profile_lay = (LinearLayout) row.findViewById(R.id.profile_lay);

            row.setTag(holder);

        } else {
            holder = (ViewHolder) row.getTag();
        }
        Products_With_ProfileModel item = expandableListTitle.get(listPosition);
        holder.user_id.setText(item.getUser_id());
        holder.name.setText(item.getName());
        holder.shop_name.setText(item.getShop_name());
        holder.location.setText(item.getLocation());
        holder.min_qty.setText(" \u20B9 " + item.getMin_qty() + " min order");
        holder.image.setImageDrawable(null);

        Picasso.get()
                .load(item.getImage())
                .fit().centerCrop()
                .into(holder.image);

        holder.pro_img.setImageDrawable(null);
        Picasso.get()
                .load(item.getPro_img())
                .fit().centerCrop()
                .into(holder.pro_img);


        holder.shop_name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Products_With_Profile.this, Vendor_Profile_With_Products_For_Main.class);
                intent.putExtra("_id", item.getUser_id());
                intent.putExtra("pro_id", pro_id);
                intent.putExtra("name", catname);
                intent.putExtra("sub_pro_id", sub_pro_id);
                intent.putExtra("category_pro_url", category_pro_url);
                startActivity(intent);
            }
        });

        holder.pro_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Products_With_Profile.this, Vendor_Profile_With_Products_For_Main.class);
                intent.putExtra("_id", item.getUser_id());
                intent.putExtra("pro_id", pro_id);
                intent.putExtra("name", catname);
                intent.putExtra("sub_pro_id", sub_pro_id);
                intent.putExtra("category_pro_url", category_pro_url);
                startActivity(intent);
            }
        });

        holder.image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Products_With_Profile.this, Vendor_Profile_With_Products_For_Main.class);
                intent.putExtra("_id", item.getUser_id());
                intent.putExtra("pro_id", pro_id);
                intent.putExtra("name", catname);
                intent.putExtra("sub_pro_id", sub_pro_id);
                intent.putExtra("category_pro_url", category_pro_url);
                startActivity(intent);
            }
        });

        return row;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int listPosition, int expandedListPosition) {
        return true;
    }

    @Override
    public Filter getFilter() {
        return null;
    }
}

0 个答案:

没有答案