首页 > 代码库 > listview 选择后高亮显示
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; }}
lv_superclass.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { adapterParent.setSelectItem(position); adapterParent.notifyDataSetInvalidated(); } });
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>
选择器
<?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>
listview 选择后高亮显示
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。