2017-05-24 69 views
-1

我必须在ListView中设置可绘制图像到图像视图。我正在使用基础适配器类。图像没有显示在图像视图,如果其他条件

有两种类型的问题,我面对:

    1. 如果我设置的图像,直到category_id.equals(2) (这里只有1如果else语句) 那么其显示图像在其他条件仅
  • 如果我设置图像的所有直到category_id.equals(7) (这里多个if,否则如果COND ition) 然后它根本没有显示任何图像。

为什么发生这种情况?我无法得到它。请帮助我...

任何帮助是非常可观的。

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; 
} 
+1

的equals()方法采取String作为参数。看起来像这里你将整数作为参数。 –

+0

@ msh.nayan什么是nonsens ...它需要Object not String – Selvin

+0

你知道我们在java中有'switch'语句吗? – Selvin

回答

0

使用==比较整数时

相关问题