根据if else条件,图像未显示在imageview中

问题描述 投票:-1回答:1

我必须将可绘制图像设置为listview中的imageview。我正在使用基础适配器类。

我面临两种类型的问题:

  • 如果我将图像设置为category_id.equals(2)(这里只有1 if else语句)那么它只在else条件下显示图像
  • 如果我为所有人设置图像,直到category_id.equals(7)(这里是多个if,否则如果条件有问题)那么它根本没有显示任何图像。

为什么会这样?我无法得到它。请帮帮我...

任何帮助都非常值得一提。

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;
}
android if-statement imageview picasso android-glide
1个回答
0
投票

比较整数时使用==

© www.soinside.com 2019 - 2024. All rights reserved.