Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 是否可以仅为listview中的特定项目着色?_Android_Listview - Fatal编程技术网

Android 是否可以仅为listview中的特定项目着色?

Android 是否可以仅为listview中的特定项目着色?,android,listview,Android,Listview,我有个问题。我有一个对象数组,已将其添加到ArrayAdapter和listview中的适配器中。我的listView在奇数位置上用一种颜色着色,在另一种颜色上用偶数着色。 现在是棘手的部分。 我的对象由字符串id和名称、字符串注释和日期组成。 我可以给预设了id/名称的条目上色吗? 例如,如果我登录并希望查看listview,则我出现的条目(我已使用共享首选项保留了id)将以另一种颜色显示。从5个条目中,比方说,我出现在其中3个条目中的任意位置。如何给我出现的位置上色 谢谢大家! 我也做了类似

我有个问题。我有一个对象数组,已将其添加到ArrayAdapter和listview中的适配器中。我的listView在奇数位置上用一种颜色着色,在另一种颜色上用偶数着色。 现在是棘手的部分。 我的对象由字符串id和名称、字符串注释和日期组成。 我可以给预设了id/名称的条目上色吗? 例如,如果我登录并希望查看listview,则我出现的条目(我已使用共享首选项保留了id)将以另一种颜色显示。从5个条目中,比方说,我出现在其中3个条目中的任意位置。如何给我出现的位置上色


谢谢大家!

我也做了类似的事情。我想更改字体颜色而不是整个项目,但您可以用您的代码替换我的代码

@Override
public View getView(int position, View v, ViewGroup parent)
{
    View mView = v ;
    if(mView == null){
        LayoutInflater vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mView = vi.inflate(id, null);
    }

    TextView text = (TextView) mView.findViewById(R.id.textView);

    if(items.get(position) != null ) //here you can match IDs and change the accordingly 
    {
        text.setTextColor(Color.WHITE);
        text.setText(items.get(position));
        text.setBackgroundColor(Color.RED); 
        int color = Color.argb( 200, 255, 64, 64 );
            text.setBackgroundColor( color );

    }

    return mView;
}

覆盖
getView
检查此解决方案是否有帮助:您需要构建自定义适配器。您可以根据每个位置的列表项数据指定适配器中的视图更改