WPF里,如何修改ListView的指定行的字体颜色和背景颜色?
比如我想把状态为“空闲”的行的字体颜色变为绿色,背景颜色变为灰色,该怎么设置呢?(注意,跟选中不选中没关系哦!)...
比如我想把状态为“空闲”的行的字体颜色变为绿色,背景颜色变为灰色,该怎么设置呢?(注意,跟选中不选中没关系哦!)
展开
2个回答
展开全部
这个可以实现啊,大概的思路是在你的listview里显示数据的时候做判断(可以用一个布尔型的数据作为标志),然后当你的适配器的数据发生变化的时候,调用niti....方法就可以,这个跟选中的实现差不多的
package com.megoc.menu;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class ListAdapter extends BaseAdapter {
private List<MaxType> list;
private LayoutInflater inflater;
private boolean is=true;
private int i=0;
public ListAdapter(Context context,List<MaxType> list){
this.list=list;
inflater=LayoutInflater.from(context);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return list.get(arg0);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View view = convertView;
final ViewHolder holder;
if(convertView==null){
view=inflater.inflate(R.layout.left_menu, null);
holder = new ViewHolder();
holder.title=(TextView) view.findViewById(R.id.title);
holder.groupx=(TextView) view.findViewById(R.id.groupx);
view.setTag(holder);
}else {
holder = (ViewHolder) view.getTag();
}
if(is){
holder.title.setText(list.get(position).getTitlech());
}else {
holder.title.setText(list.get(position).getTitleng());
}
holder.groupx.setText(list.get(position).getGroupx());
if(position==i){
view.setBackgroundColor(0xFFaaccdd);
}else {
view.setBackgroundColor(0xFFFFFFFF);
}
return view;
}
private class ViewHolder {
TextView title;
TextView groupx;
}
public void changel(boolean choren) {
is=choren;
notifyDataSetChanged();
}
public void clickchange(int i) {
this.i=i;
notifyDataSetChanged();
}
}
package com.megoc.menu;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class ListAdapter extends BaseAdapter {
private List<MaxType> list;
private LayoutInflater inflater;
private boolean is=true;
private int i=0;
public ListAdapter(Context context,List<MaxType> list){
this.list=list;
inflater=LayoutInflater.from(context);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return list.get(arg0);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View view = convertView;
final ViewHolder holder;
if(convertView==null){
view=inflater.inflate(R.layout.left_menu, null);
holder = new ViewHolder();
holder.title=(TextView) view.findViewById(R.id.title);
holder.groupx=(TextView) view.findViewById(R.id.groupx);
view.setTag(holder);
}else {
holder = (ViewHolder) view.getTag();
}
if(is){
holder.title.setText(list.get(position).getTitlech());
}else {
holder.title.setText(list.get(position).getTitleng());
}
holder.groupx.setText(list.get(position).getGroupx());
if(position==i){
view.setBackgroundColor(0xFFaaccdd);
}else {
view.setBackgroundColor(0xFFFFFFFF);
}
return view;
}
private class ViewHolder {
TextView title;
TextView groupx;
}
public void changel(boolean choren) {
is=choren;
notifyDataSetChanged();
}
public void clickchange(int i) {
this.i=i;
notifyDataSetChanged();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询