更改Android列表视图项的颜色 [英] Android Change the color of List view Item

查看:140
本文介绍了更改Android列表视图项的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

   final SimpleAdapter adapter = new SimpleAdapter(getActivity(),
                    itemlist, R.layout.listview_custom_view_sales_products,
                    new String[] { "Number", "item_name", "qty" }, new int[] {
                            R.id.number, R.id.Name, R.id.value }) {

                public View getView(int position, View convertView, ViewGroup parent) {
                    View view = super.getView(position, convertView, parent);

                    HashMap<String, String> obj = (HashMap<String, String>) getListView().getAdapter().getItem(position);



                for (String x : added_items) {

                      if (String.valueOf(x).equals(obj.get("item_name").toString())) {

                            Log.i("sdsds", "working");

                            view.setBackgroundColor(Color.BLUE);

                        }

                    } 

                    return view;

                };
            };

下面我根据物品使用上述code颜色项目列入 addeditem (这是数组),但我的问题是,它改变了色彩那些没有新我wArrayList添加其它行的意见。

Here I used the above code to color items according to the items included in addeditem(it is array).But my problem is that it changes the color of the other row views which were not newly added in my wArrayList.

推荐答案

您需要做的:

            public View getView(int position, View convertView, ViewGroup parent) {
                View view = super.getView(position, convertView, parent);
                String word=yourArrayOfStrings[position];
                if(word.equals("item_...")){
                    view.setBackgroundColor(Color.BLUE);

                }
                return view;
            }

这篇关于更改Android列表视图项的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆