80,351
社区成员
发帖
与我相关
我的任务
分享
if (position == datas.size()-1) {
item.schedule_line.setBackgroundColor(Color.WHITE);
} else {
item.schedule_line.setBackgroundColor("此处需要设置为默认颜色");
}
[/quote]
干的漂亮,想通了,3Q!
错误原因:position == datas.size()-1这个方法我也试过,结果不对,还以为是错的。而且我是要同一个listview里切换着显示3个不同的datas的,当时我是这样的
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
view = View.inflate(mContext, R.layout.item_schedule, null);
//这里是写了很多布局代码
if(position == datas.size()-1){
item.schedule_line.setBackgroundColor(Color.WHITE);
}
view.setTag(item);
} else {
item = (ScheduleItem) view.getTag();
}
//这里写了textview之类的控件的内容的赋值语句
return view;
}
解决办法:1、赋值的语句放到view == null判断外。2、切换时,其他item要还原到默认状态
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
view = View.inflate(mContext, R.layout.item_schedule, null);
//这里是写了很多布局代码
view.setTag(item);
} else {
item = (ScheduleItem) view.getTag();
}
//这里写了textview之类的控件的内容的赋值语句
if(position == datas.size()-1){
item.schedule_line.setBackgroundColor(Color.WHITE);
}else{
item.schedule_line.setBackgroundColor("此处需要设置为默认颜色");
}
return view;
}
if (position == datas.size()-1) {
item.schedule_line.setBackgroundColor(Color.WHITE);
} else {
item.schedule_line.setBackgroundColor("此处需要设置为默认颜色");
}