zoukankan      html  css  js  c++  java
  • 设置单选的listView或者gridview

    主要是这个BeaseAdapter的方法notifyDataSetChanged()的使用;
    作用 :调用BaseAdapter中的getView();方法,刷新ListView中的数据。
    实现:1.在BaseAdapter里面定义全局变量 int selectIndex;
    2.为listView添加setOnItemClickListener()事件:里面改变selectIndex的值==》
    listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view,
    int position, long id) {
    //选中时改变颜色
    adapter.selectIndex=position;
    adapter.notifyDataSetChanged();
    }
    });

    2.在getView()方法里面加上一个if:
    if( selectIndex == position ){
    view.setBackgroundColor(Color.parseColor("#82eae8"));
    }else{
    view.setBackgroundColor(Color.alpha(0));
    }
    }
  • 相关阅读:
    such用法
    divorce用法
    towel用法
    go for用法
    catch on用法
    incredibly用法
    mess用法
    dentist用法
    steer clear of用法
    incredible
  • 原文地址:https://www.cnblogs.com/shoneworn/p/5796338.html
Copyright © 2011-2022 走看看