0
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    View gridView;
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(
                      Context.LAYOUT_INFLATER_SERVICE);
        gridView = new View (mContext);
        gridView = inflater.iflate(R.layout.gridview_item,null);
    }else {
        gridView = convertView;
    }
    TextView textView = (TextView)
    gridView.findViewById(R.id.grid_item_text);
    textView.setText(mThumbIds_Strings[position]);
    ImageView imageView = (ImageView) gridView.findViewById(R.id.grid_item_image);
    imageView.setImageResource(mThumbIds[position]);
    return gridView;
}

我们想做inflate。我们将使用gridview_item已经存在并且是Gridview. 当我尝试运行此代码时,会出现以下错误:

LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(
    Context.LAYOUT_INFLATER_SERVICE);

TextView textView = (TextView)

ImageView imageView = (ImageView)
4

1 回答 1

0

嘿,你没有给出错误日志,但我认为问题出在 inflate 方法上,如下所示进行更改。除此之外不需要gridView = new View (mContext);

   @Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    View gridView;
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        gridView = inflater.inflate(R.layout.gridview_item, parent, false);
    }else {
        gridView = convertView;
    }
    TextView textView = (TextView)
    gridView.findViewById(R.id.grid_item_text);
    textView.setText(mThumbIds_Strings[position]);
    ImageView imageView = (ImageView) gridView.findViewById(R.id.grid_item_image);
    imageView.setImageResource(mThumbIds[position]);
    return gridView;
}
于 2013-09-26T18:03:17.090 回答