android 微调器更改特定项目的背景颜色
android spinner change the background color for specific items
我有一个微调器,我想更改特定项目的背景颜色。我的意思是,如果对象被命名为:country 并且它具有值 section=true
那么微调器的项目将具有背景 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
我该怎么做。
在您的 getView()
方法中,您可以执行以下操作:
if (yourCondition) {
tv.setBackgroundColor(getContext().getResources().getColor(R.color.blue));
}
这应该可以解决问题。
@更新
如果我没看错,你想在 getView()
方法中获取当前项目,对吗?
我假设您的适配器正在扩展 ArrayAdapter<T>
。如果是这种情况,您可以使用 ArrayAdapter getItem(position)
方法获取项目并像这样进行测试:
if ((getItem(position)).isSection()) { }
在你的getView()
.
里面
希望对您有所帮助。
试试这个:
if (report.isSection())
tv.setBackgroundColor(Color.parseColor("#0D47A1"));
看了你的问题,我了解到你想访问列表中的项目。好吧,这就是你如何做到这一点:
@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(getContext().getResources().getColor(R.color.blue));
//here is how will you access your list: let say, your data list name is "itemList"
item=itemList.get(position);//it will return the item from that list
}
我有一个微调器,我想更改特定项目的背景颜色。我的意思是,如果对象被命名为:country 并且它具有值 section=true
那么微调器的项目将具有背景 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
我该怎么做。
在您的 getView()
方法中,您可以执行以下操作:
if (yourCondition) {
tv.setBackgroundColor(getContext().getResources().getColor(R.color.blue));
}
这应该可以解决问题。
@更新
如果我没看错,你想在 getView()
方法中获取当前项目,对吗?
我假设您的适配器正在扩展 ArrayAdapter<T>
。如果是这种情况,您可以使用 ArrayAdapter getItem(position)
方法获取项目并像这样进行测试:
if ((getItem(position)).isSection()) { }
在你的getView()
.
希望对您有所帮助。
试试这个:
if (report.isSection())
tv.setBackgroundColor(Color.parseColor("#0D47A1"));
看了你的问题,我了解到你想访问列表中的项目。好吧,这就是你如何做到这一点:
@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(getContext().getResources().getColor(R.color.blue));
//here is how will you access your list: let say, your data list name is "itemList"
item=itemList.get(position);//it will return the item from that list
}