I'm creating a custom gridView and I need to have an image and a text for the elements of the gridView. I have this adapter for the gridView but I can't solve the error I have:
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
/**
*
* @author manish.s
*
*/
public class CustomGridViewAdapter extends ArrayAdapter<Item> {
Context context;
int layoutResourceId;
ArrayList<Item> data = new ArrayList<Item>();
public CustomGridViewAdapter(Context context, int layoutResourceId,
ArrayList<Item> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
RecordHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new RecordHolder();
holder.txtTitle = (TextView) row.findViewById(R.id.item_text);
holder.imageItem = (ImageView) row.findViewById(R.id.item_image);
row.setTag(holder);
} else {
holder = (RecordHolder) row.getTag();
}
Item item = data.get(position);
holder.txtTitle.setText(item.getTitle());
holder.imageItem.setImageBitmap(item.getImage());
return row;
}
static class RecordHolder {
TextView txtTitle;
ImageView imageItem;
}
}
The error I have is here:
holder.txtTitle.setText(item.getTitle());
holder.imageItem.setImageBitmap(item.getImage());
It says: The method item.getTitle (and also item.getImage) is undefined for the type ClipData.Item
What am I missing?
答案 0 :(得分:0)
错误非常具体:您没有为ClipData.Item定义您使用的方法。
对于文本,请尝试使用:
holder.txtTitle.setText(item.getText());
对于图像,它实际上取决于你构建项目的方式。