I am have to set drawable images to an imageview in a listview.I am using base adapter class. There are two types of problem i am facing: 1.if i am setting image till category_id.equals(2) (here only 1 if else statement) then its showing the image in else condition only 2.if i am setting image for all till category_id.equals(7) (here multiple if,else if condition as in question) then its not showing any images at all.
Why it is happening??I am not able to get it.Please help me...Any help is greatly appreciable.
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;
}
Aucun commentaire:
Enregistrer un commentaire