2017-05-24 26 views
-1

drawable画像をリストビューの画像ビューに設定する必要があります。私はベースアダプタクラスを使用しています。私は(2) (ここでの唯一の1 else文の場合) その画像を示すcategory_id.equalsまでの画像を設定していた場合画像が他の条件で画像ビューに表示されない

    1. は、私が直面しています、問題の2つのタイプがあります。他の条件でのみ

  • 私はcategory_id.equalsまですべてのための画像を設定していた場合(7)
      (ここでは、他の複数の場合は、cond場合問題のように) その画像を全く表示していません。

なぜそれが起こっているのですか?私はそれを得ることができません。私を助けてください...

どんな助けも大いに受け入れられます。

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()メソッドは、パラメータとして文字列を取ります。ここではIntegerをパラメータとして使用しています。 –

+0

@ msh.nayan何が起こっていないのか...オブジェクトには文字列ではない – Selvin

+0

javaで 'switch'文があることは知っていますか? – Selvin

答えて

0

使用==比較する整数が

関連する問題