简体   繁体   English

为每个列表视图行指定颜色

[英]Specify color for each listview row

I fill my ListView with this code: 我用以下代码填充ListView:

    final ListView lv = (ListView) findViewById(R.id.lvKinder);
    ArrayList<Kind> kisi = datenfuerlistview();
    KinderlistAdapter kiadapter = new KinderlistAdapter(this, kisi);
    lv.setAdapter(kiadapter);
    final DBHelper db = new DBHelper(this);

Now I want to analyse one entry of every Kind object I add to my ListView . 现在,我要分析添加到ListView的每个Kind对象的一个​​条目。 If it has a certain value, I want to change the backgroundcolor for this ListView entry. 如果它具有某个值,我想更改此ListView条目的背景色。

Here´s my adapter: 这是我的适配器:

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if(convertView == null){
            convertView = inflator.inflate(R.layout.list_black_text, parent, false);
            holder = new ViewHolder((TextView) convertView.findViewById(R.id.nullline), (TextView) convertView.findViewById(R.id.firstLine), (ImageView) convertView.findViewById(R.id.imgv));

            convertView.setTag(holder);
        }
        else{
            holder = (ViewHolder) convertView.getTag();
        }

        Kind ki = (Kind) getItem(position);
        holder.getName().setText(ki.getName());
        holder.getDatum().setText(ki.getDatum());

        Uri uri = Uri.parse(ki.getGeschlecht());

        String path = ki.getKinderbild();

        System.out.println("HSSSSSSSSSSSSSSSSSSSSSS" + path);
        //holder.getGeschlecht().setImageBitmap(bitmap);

        ContentResolver cr = context.getContentResolver();
        Bitmap tmp = null;
        try {
            tmp = getThumbnail(cr, path);
        } catch (Exception e) {
            System.out.println("NAAAAAAAAAAAAAAAAAAAA") ;
            e.printStackTrace();
        }

        holder.getGeschlecht().setImageBitmap(tmp);

        return convertView;

How to set the color? 如何设置颜色?

Did you tried this ? 你试过这个吗? (before returning convertView) : (在返回convertView之前):

convertView.setBackgroundColor(Color.BLUE);//or another color

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM