Android的Master/Detail风格界面中实现自定义ListView的单选
原文在这里:http://duduli.iteye.com/blog/1453576
可以实现多选,那么如何实现单选呢,这里我写了一个非常简单的方法:
public void onListItemClick(ListView listView, View view, int position, long id) {
super.onListItemClick(listView, view, position, id);
CheckedTextView ct;
CheckedTextView multiple;
int count = listView.getChildCount();
for (int i = 0 ; i < count ; i ++ ) {
ct = (CheckedTextView)listView.getChildAt(i).findViewById(R.id.checkText);
ct.setChecked(false);
}
multiple = (CheckedTextView)view.findViewById(R.id.checkText);
multiple.toggle();
}
当然,你需要在你自定义的Adapter的getView()里面
holder.checkedTextView = (CheckedTextView)convertView.findViewById((R.id.checkText));
这里是我定义的ListView中每个View的xml布局
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"> <ImageView
android:layout_width="wrap_content"
android:padding="0dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="@drawable/navigation_category_icon"
android:id="@+id/imageView"
android:layout_gravity="center_horizontal|top"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Large Text"
android:id="@+id/textView"
android:layout_gravity="center_horizontal|top"
android:layout_toRightOf="@+id/imageView"
android:layout_marginBottom="11dp"/>
<CheckedTextView
android:id="@+id/checkText"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:paddingLeft="6dip"
android:paddingRight="6dip"
/>
</RelativeLayout>
这里是效果图
Android的Master/Detail风格界面中实现自定义ListView的单选的更多相关文章
- 在cocos2d-x界面中嵌入Android的WebView
在Cocos2dxActivity.java中, (1) 增加函数onCreateLayout, [java] view plain copy public LinearLayout onCre ...
- Android 在界面中显示以及输入文本信息 TextView和EditText
Android控件之TextView和EditTextTextView:显示文本框控件EditText:输入文本框TextView和EditText的常用属性TextView控件的常用属性androi ...
- Android UI 之 Tab类型界面总结
Android 程序中实现Tab类型界面很常见,本人在做项目的时候也经常用到,所以想在这里总结一下,实现tab类型界面的几种方式,供大家参考.如有不对之处,欢迎大家指正! 一.TabActivity ...
- Android主题theme和风格style总结
用到了Android的主题和风格,感觉很多地方需要总结和记录下来.其实主题和风格是有很大的作用的,特别是界面要求比较高的客户端. Style:是一个包含一种或者多种格式化属性的集合,我们可以将其用为一 ...
- Android Studio设置Eclipse风格快捷键
Android Studio的1.1.0版本都发布了,ADT也不会再更新了,童鞋们还有理由不换嘛,不要死守着Eclipse了,Android Studio是你唯一的也是最好的选择.什么?用Eclips ...
- Android基础之——startActivityForResult启动界面并返回数据,上传头像
在android应用的开发过程中,常常会出现启动一个界面后填写部分内容后带着数据返回启动前的界面,最典型的应用就是登录过程.在非常多应用程序的模块中,都有"我的"这个模块,在未登录 ...
- Android开发优化之——对界面UI的优化(1)
在Android应用开发过程中,屏幕上控件的布局代码和程序的逻辑代码通常是分开 的.界面的布局代码是放在一个独立的xml文件中的,这个文件里面是树型组织的,控制着页面的布局.通常,在这个页面中会用到很 ...
- (转)Android项目重构之路:界面篇
在前一篇文章<Android项目重构之路:架构篇>中已经简单说明了项目的架构,将项目分为了四个层级:模型层.接口层.核心层.界面层.其中,最上层的界面,是变化最频繁的一个层面,也是最复杂最 ...
- [Android] Android开发优化之——对界面UI的优化(2)
在Android应用开发过程中,屏幕上控件的布局代码和程序的逻辑代码通常是分开的.界面的布局代码是放在一个独立的xml文件中的,这个文件里面是树型组织的,控制着页面的布局.通常,在这个页面中会用到很多 ...
随机推荐
- 修改系统时间为UTC时间
1 拷贝时区文件 cp /usr/share/zoneinfo/Etc/GMT /etc/localtime 2 修改/etc/profile 在最后添加 TZ="Etc/GMT" ...
- Java容器---Arrays & Collections工具类
1.Array & Arrays 与Collection & Collections区别 (1)Collection": 是一个接口,与其子类共同组成一个Collection ...
- Tutorial: Reverse debugging with GDB 7 (转载)
Tutorial: Reverse debugging with GDB 7 Tutorial: Reverse debugging with GDB 7 by Jay Conrod posted o ...
- scala学习笔记4--scala的函数一
默认值: def sayMyName(name : String = "Jack"){ println(name) } 可变参数: def sumMoreParameters(el ...
- scala windows 安装
下载 https://downloads.lightbend.com/scala/2.11.11/scala-2.11.11.msi 第一步:设置 右击我的电脑,单击"属性",进入 ...
- hdu4347
求与询问点欧几里德距离前m小的点 其实就是在kdtree询问的时候用优先队列维护一下就好了 好久没写kdtree练一练,注意这道题是多测 #include<bits/stdc++.h> u ...
- 06 java 基础:java 循环 递归
1 递归实现 1 + 2 +3 +4 +5 + .... +100 public static int addSum(int num){ if(num == 1) return 1; return n ...
- LoadRunner函数–lr_vuser_status_message
http://wenku.baidu.com/link?url=KbKGldKUkam4VyH5Z2doesA0ovQpuwM9nX_SnVMtWjo6rJPxj9DqB51z_m1giMbVo5Db ...
- IntelliJ IDEA 编译程序出现 非法字符 的 解决方法(转)
百度到很多方法,比如(删了文件重新建:先改成GBK再UTF8:粘贴到notpad++上改utf8),但都没有解决问题.下面这种方法确实有效,先记下来,如果有其他好方法将来在补充…… 文章来源: ht ...
- 可随意交换位置的gridview
自定义gridview import android.app.Activity; import android.content.Context; import android.graphics.Poi ...