zoukankan      html  css  js  c++  java
  • listview 选择后高亮显示

    public class UserTypeParentAdapter extends MyBaseAdapter<UserTypeList> {
        private int selectItem = -1;
    
        public UserTypeParentAdapter(Context context, List<UserTypeList> datas) {
            super(context, datas);
        }
    
        public void setSelectItem(int selectItem) {
            this.selectItem = selectItem;
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.usertype_superclass_item,null);
            }
            TextView txtTitle = ViewHolder.get(convertView, R.id.txt_title);
            txtTitle.setText(mDatas.get(position).getTypename());
            if (position == selectItem) {
                txtTitle.setSelected(true);
                txtTitle.setEnabled(true);
            } else {
                txtTitle.setSelected(false);
                txtTitle.setEnabled(false);
            }
            return convertView;
        }
    
    }
    View Code
        lv_superclass.setOnItemClickListener(new OnItemClickListener() {
    
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    adapterParent.setSelectItem(position);  
                    adapterParent.notifyDataSetInvalidated();  
                }
            });
    View Code

    adapter item布局

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="50.0dip"
        android:orientation="vertical" >
    
        <TextView 
            android:id="@id/txt_title"
            android:layout_width="match_parent"
            android:layout_height="50.0dip"
            android:background="@drawable/usertype_super_select"
            android:drawableRight="@drawable/arrows_identity_select"
            android:gravity="center"
            android:textColor="@color/login_font"
            android:textSize="16.0sp" />
    
    </LinearLayout>
    View Code

    选择器

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:state_enabled="true" android:state_focused="true" android:drawable="@color/white"></item>
        <item android:state_enabled="true" android:state_selected="true" android:drawable="@color/white"></item>
        <item android:state_pressed="true" android:drawable="@color/white"></item>
        <item android:drawable="@color/layout_bg"></item>
    
    </selector>
    View Code
  • 相关阅读:
    Nginx 反向代理、负载均衡、页面缓存、URL重写及读写分离详解
    大型网站系统架构技术原理透析
    大中型网站架构探秘
    大型网站架构不得不考虑的10个问题
    (推荐)高并发高流量网站架构详解
    可扩展、高可用、负载均衡网站架构设计方案
    nginx内置常用变量
    Linux下nginx支持.htaccess文件实现伪静态的方法!
    扩展js,实现c#中的string.format方便拼接字符串
    Winform退出运行后,删除运行目录(批处理方法)
  • 原文地址:https://www.cnblogs.com/freexiaoyu/p/4148165.html
Copyright © 2011-2022 走看看