使用If语句设置Image ListView

时间:2015-11-23 12:26:03

标签: android listview

我有一个带有动态列表项长度的图像列表视图,我只有3个图像但是图像只能在每个项目上设置IF状态值是OK,OFFLINE或PENDING,我如何使用IF ELSE IF和ELSE设置每个列表视图项中的3个图像之一,我的代码示例如下:

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

0 个答案:

没有答案