ListView not checking items on Android 1.5
I'm developing an app for Android in Eclipse. Currently I target API level 3, but I was mistakenly testing on an Android 1.6 emulator (API level 4). On 1.6 it worked fine, but on 1.5 my ListView with CHOICE_MODE_SINGLE does not select items when they are clicked on.
Here's my listview XML:
<ListView
android:layout_height="wrap_content"
android开发者_StackOverflow社区:layout_width="fill_parent"
android:layout_weight="1"
android:id="@+id/ListDomains"
android:layout_margin="5px"
android:choiceMode="singleChoice"
android:clickable="false"
android:focusable="true"
android:focusableInTouchMode="true"
android:descendantFocusability="beforeDescendants"
>
</ListView>
Here's the XML for the items in the listview:
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:id="@+id/domain_list_value"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="fill_parent"
>
</CheckedTextView>
I created a custom ArrayList adapter to let me customize getView. Here's the code for DomainArrayAdapter:
public class DomainArrayAdapter extends ArrayAdapter<char[]> {
private LayoutInflater mInflater;
public DomainArrayAdapter(Context context, int textViewResourceId,
List<char[]> objects) {
super(context, textViewResourceId, objects);
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){
convertView = mInflater.inflate(R.layout.domain_list, null);
}
char[] text = super.getItem(position);
((CheckedTextView)convertView).setText(text, 0, text.length);
return convertView;
}
}
All of this code works fine compiled against API level 3 and run on an Android 1.6 emulator. However, run against a 1.5 emulator, items in the ListView do not check when clicked on.
Any ideas?
It appears Android 1.5 does not respect the choiceMode set in the listview XML. Setting it programatically causes it to work correctly:
ListView listDomains = (ListView) findViewById(R.id.ListDomains);
Log.d("app", String.valueOf(listDomains.getChoiceMode())); //prints 0
listDomains.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
Log.d("app", String.valueOf(listDomains.getChoiceMode())); //prints 1
Has anyone else seen this sort of behavior?
精彩评论