开发者社区 问答 正文

int和Integer之间转换老报错 ?报错

int和Integer之间转换老报错,改为parseInt,valueOf等等都不行,快崩溃了
图片说明

 package com.example.shop;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public abstract class CommonAdapter<Integer> extends BaseAdapter {

    protected LayoutInflater mInflater;
    protected boolean conver = true;
    protected int mItemLayoutId;
    protected List<Integer> mList;
    protected Context context;

    public CommonAdapter(Context context, List<Integer> list, int itemLayoutId) {
        this.mItemLayoutId = itemLayoutId;
        this.context = context;
        this.mList = list;
        this.mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public Integer getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemViewType(int position) {
        return IGNORE_ITEM_VIEW_TYPE;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CommonViewHolder viewHolder = CommonViewHolder.get(context,
                convertView, parent, mItemLayoutId, position);
        convert(viewHolder, position, getItem(position));
        return viewHolder.getConvertView();
    }

    public  void convert(CommonViewHolder holder, int position, Integer item)
    {

        if (item==0)
            holder.getView(R.id.rl_0).setVisibility(View.VISIBLE);
        else if(item==1)
            holder.getView(R.id.rl_1).setVisibility(View.VISIBLE);
    }

}

展开
收起
爱吃鱼的程序员 2020-06-23 01:30:10 750 分享 版权
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
    if(item.intValue()==0)

    Integer是包装类,所以不能直接==,可以通过一楼方法获取其int值。类似的list<>中需要类参数,不能使用int需要使用integer

    之前说的有问题integer是能直接进行数值判断的,这里有两种解决方案,
    第一种

    第二种

    你JDK版本太低了,,至少到jdk7就可以使用了

    2020-06-23 01:30:27
    赞同 展开评论
问答地址: