Android的微调改变背景颜色为具体项目 [英] android spinner change the background color for specific items
问题描述
我有一个微调,我想改变背景颜色的具体项目。我的意思是,如果该对象被命名为:国家,如果它有值部分= TRUE
所以微调的项目将有背景颜色=蓝色
。
i have a spinner , i want to change the background color for specific items. i mean if the object is named: country and if it have value section=true
so the item of spinner will have background color = blue
.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final kamcoReportType report = values.get(position);
if (convertView == null) {
Context mContext = this.getContext();
LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
TextView tv=(TextView) convertView.findViewById(R.id.TextView01);
if (report.isSection())
tv.setBackgroundColor=blue //what ever
我怎么能做到这一点。
how can i do that.
推荐答案
在你的 getView()
方法,你可以这样做:
On your getView()
method you can do:
if (yourCondition) {
tv.setBackgroundColor(getContext().getResources().getColor(R.color.blue));
}
这应该可以解决问题。
@UPDATE
如果我有你的权利,你想要得到你的 getView()
方法的当前项目,对吧?
If I got you right, you want to get the current item on your getView()
method, right?
我假设你的适配器扩展 ArrayAdapter< T>
。如果是这样的话,你可以使用ArrayAdapter 的getItem(位置)
方法,让您的项目并对其进行测试,如:
I assume your adapter is extending ArrayAdapter<T>
. If this is the case, you can get your items using ArrayAdapter getItem(position)
method and test it like:
if ((getItem(position)).isSection()) { }
在你的 getView()
。
希望这有助于。
这篇关于Android的微调改变背景颜色为具体项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!