listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
请问下我单独显示setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_single_choice, GENRES));
一个数据的时候可以用setChoiceMode 每一个item后面出现一个单选按钮
但是我自己定义个adapt 例如 setListAdapter(new ImageAdapter(this) );
在使用listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
在每个item 后面就不会出现单选按钮 请高手指点为啥出现这种原因我该
怎么作才可以把单选按钮宣示出来.....
请问下我单独显示setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_single_choice, GENRES));
一个数据的时候可以用setChoiceMode 每一个item后面出现一个单选按钮
但是我自己定义个adapt 例如 setListAdapter(new ImageAdapter(this) );
在使用listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
在每个item 后面就不会出现单选按钮 请高手指点为啥出现这种原因我该
怎么作才可以把单选按钮宣示出来.....
none 0 Normal list that does not indicate choices
singleChoice 1 The list allows up to one choice
multipleChoice 2 The list allows multiple choices
hackkuang001和shang19875366就一个人 ,是吧
我查看了一下系统源码,里面你所用的android.R.layout.simple_list_item_single_choice这个布局,代码如下(内容原因,只贴出关键部分<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:paddingLeft="6dip"
android:paddingRight="6dip"
/>你可以看出,你用系统的adapter有单选按钮原因在于,系统的adapter绑定了系统的android.R.layout.simple_list_item_single_choice,而你自定义的adapter中,想必楼主没有这样做。
解决办法:建议楼主在你自定义的adapter中的getView()方法中绑定这个控件即可。
我自己写了一个checkbox 可以显示出来但是实现不了单选
我的设置如下layout是这样设置的 android:choiceMode="singleChoice" 原码里面是这样设置的:
mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
然后你还得在你具体的布局里面, 实例化CheckBox对象并且绑定 , 在相应的地方做它的逻辑嘛
holder.text = (TextView) convertView.findViewById(R.id.text);
holder.icon = (ImageView) convertView.findViewById(R.id.icon);
holder.check =(RadioButton) convertView.findViewById(R.id.RadioButton01);
我是显示一个图片一个文字一个单选按钮
现在是可以显示出单选按钮 但是就是不知道绑定对象 和实现逻辑
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:paddingLeft="6dip"
android:paddingRight="6dip"
/>这里是系统的那个layout 但是他那样设置就可以我的就不行
实在郁闷
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
> <ImageView android:id="@+id/icon"
android:background="?android:attr/galleryItemBackground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/> <TextView android:id="@+id/text"
android:layout_gravity="center_vertical"
android:layout_width="0dip"
android:layout_weight="1.0"
android:layout_height="wrap_content" />
<RadioButton
android:id="@+id/RadioButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:paddingRight="10dip"
android:choiceMode="singleChoice"
>
</RadioButton>
</LinearLayout>