Listview高亮,是焦点回滚还是高亮

来源:互联网 发布:python字符串内置函数 编辑:程序博客网 时间:2024/06/02 13:21

大家做滚动时要显示选中项,使他高亮,但该项失去焦点回滚,高亮就消失。网上好多关于这个的问题,但是都是做到一半或解决了就不回复的帖子,我的解决办法。

定义两个全部变量

public static int positionSelect = -1;//当前选中item

private View oldView = null;//当前高亮view

public static View newView = null;

 

onItemClick(AdapterView<?> arg0,View arg1, int arg2, long arg3){

positionSelect = arg2;

if (oldView == null) {
   oldView =arg1;
   oldView.setBackgroundColor(R.color.transparent);
  } else {
   oldView.setBackgroundDrawable(null);
   oldView =arg1;
   oldView.setBackgroundColor(R.color.transparent);
  }

if(newView!=null){
   newView.setBackgroundDrawable(null);
  }

}

在适配器中

getview(int position, View convertView, ViewGroup parent){

if (AnimatedSizingGallery.positionSelect == position) {
   convertView.setBackgroundColor(R.color.transparent);
   AnimatedSizingGallery.newView= convertView;
  } else {
   convertView.setBackgroundDrawable(null);
  }

}

Listview高亮,是焦点回滚还是高亮

我用两个View解决的,如果有朋友有更好的办法,麻烦给我留言,不想想了,我比较懒。

 

 

0 0
原创粉丝点击