我有一個圖像列表視圖與動態列表項目長度,我只有3個圖像,但圖像只能在每個項目上設置如果狀態值爲OK,OFFLINE或PENDING,我怎麼能使用IF ELSE IF和ELSE設置在每個列表視圖中的項的3個圖像中的一個,下面我的代碼的示例:設置圖像ListView與If語句
Integer[] imageId = {
R.drawable.round_green,
R.drawable.round_red,
R.drawable.round_grey,
};
ContactsAdapter adapter = new ContactsAdapter(this, itemTitle, itemStatus, imageId);
list.setAdapter(adapter);
list.setOnItemClickListener(this);
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View row=convertView;
if(row==null)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.activity_item, parent, false);
}
TextView tvTitle = (TextView) row.findViewById(R.id.Title);
TextView tvStatus = (TextView) row.findViewById(R.id.Status);
ImageView imageView = (ImageView) row.findViewById(R.id.imageView);
tvTitle.setText(Title.get(position));
tvStatus.setText(Status.get(position));
imageView.setImageResource(imgid[position]); //this must set either image A or B or C depending on value of text view status which can either be OK, OFFLINE or PENDING
return row;
}
如果你正在使用自定義列表查看然後提供getView()方法的代碼 – warlock
編輯顯示getView()方法 – user5174952
你在哪裏檢查狀態,我認爲這段代碼會把第一個圖像放在第一個位置第二個圖像在第二個位置等等 – warlock