我必须将可绘制图像设置为listview中的imageview。我正在使用基础适配器类。
我面临两种类型的问题:
为什么会这样?我无法得到它。请帮帮我...
任何帮助都非常值得一提。
private Activity activity;
private LayoutInflater inflater;
private List<Contents> tableofcontents;
public TocAdapter(Activity activity, List<Contents> tableofcontents) {
this.activity = activity;
this.tableofcontents = tableofcontents;
}
@Override
public int getCount() {
return tableofcontents == null ? 0 : tableofcontents.size();
}
@Override
public Object getItem(int location) {
return tableofcontents.get(location);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.tableofcontents_view, null);
ImageView thumbNail = (ImageView) convertView
.findViewById(R.id.thumbnail);
TextView name = (TextView) convertView.findViewById(R.id.name);
Contents m = tableofcontents.get(position);
String id = tableofcontents.get(position).getCategory_id();
Log.d(TAG,"m Check :"+m.getCategory_id());
Log.d(TAG,"tggCheck :"+tableofcontents.get(position).getCategory_id());
if(tableofcontents.get(position).getCategory_id().equals(1)) {
Glide.with(activity)
.load(R.drawable.novels)
.placeholder(R.mipmap.ic_launcher)
.into(thumbNail);
}else if(tableofcontents.get(position).getCategory_id().equals(2)){
Glide.with(activity)
.load(R.drawable.verses)
.placeholder(R.mipmap.ic_launcher)
.into(thumbNail);
}else if(tableofcontents.get(position).getCategory_id().equals(3)) {
Glide.with(activity)
.load(R.drawable.songs)
.placeholder(R.mipmap.ic_launcher)
.into(thumbNail);
}else if(tableofcontents.get(position).getCategory_id().equals(4)) {
Glide.with(activity)
.load(R.drawable.stories)
.placeholder(R.mipmap.ic_launcher)
.into(thumbNail);
}else if(tableofcontents.get(position).getCategory_id().equals(5)) {
Glide.with(activity)
.load(R.drawable.plays)
.placeholder(R.mipmap.ic_launcher)
.into(thumbNail);
}else if(tableofcontents.get(position).getCategory_id().equals(6)) {
Glide.with(activity)
.load(R.drawable.essay)
.placeholder(R.mipmap.ic_launcher)
.into(thumbNail);
}else if(tableofcontents.get(position).getCategory_id().equals(7)) {
Glide.with(activity)
.load(R.drawable.others)
.placeholder(R.mipmap.ic_launcher)
.into(thumbNail);
}
name.setText(m.getName());
return convertView;
}
比较整数时使用==