基本适配器中的不兼容类型错误java.lang.integer

时间:2015-12-24 06:55:33

标签: android

我对android很新,我试图在网格视图中显示图像,在我的基础适配器中我收到错误,在我的get Item方法中不兼容类型java.lang.integer任何人帮我请如何解决我的问题问题,

这里是我的适配器代码

private ArrayList<Integer> listFlag;
private Activity activity;

public GalleryAdapter(Activity activity, ArrayList<Integer> listFlag) {
    super();

    this.listFlag = listFlag;
    this.activity = activity;
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return listFlag.size();
}

@Override
public String getItem(int position) {
    // TODO Auto-generated method stub
    return listFlag.get(position);
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}

public static class ViewHolder
{
    public ImageView imgViewFlag;

}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    ViewHolder view;
    LayoutInflater inflator = activity.getLayoutInflater();

    if(convertView==null)
    {
        view = new ViewHolder();
        convertView = inflator.inflate(R.layout.gallery_viewlayout, null);

        view.imgViewFlag = (ImageView) convertView.findViewById(R.id.picture);

        convertView.setTag(view);
    }
    else
    {
        view = (ViewHolder) convertView.getTag();
    }

    //view.txtViewTitle.setText(listCountry.get(position));
    view.imgViewFlag.setImageResource(listFlag.get(position));

    return convertView;
}

提前谢谢

1 个答案:

答案 0 :(得分:0)

您的方法应该返回String但它返回Integer。 这应该可以解决问题:

@Override
public String getItem(int position) {
// TODO Auto-generated method stub
return Integer.toString(listFlag.get(position));
}