我见过ApiDemos的com.example.android.apis.view.List11示例.在该示例中,每行采用视图android.R.simple_list_item_multiple_choice.每个这样的视图都有a TextView和a CheckBox.
现在我希望每个视图都有2 TextViews和1 CheckBox,有点类似于List3示例.我尝试像这样创建一个自定义布局文件row.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<CheckBox
android:id="@+id/checkbox"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<TextView
android:id="@+id/text_name"
android:textSize="13px"
android:textStyle="bold"
android:layout_toLeftOf="@id/checkbox"
android:layout_alignParentLeft="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/text_phone"
android:textSize="9px"
android:layout_toLeftOf="@id/checkbox"
android:layout_below="@id/text_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
然后在Activitys中onCreate(),我喜欢这样:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Query the contacts
mCursor = getContentResolver().query(Phones.CONTENT_URI, null, null, null, null);
startManagingCursor(mCursor);
ListAdapter adapter = new SimpleCursorAdapter(this,
R.layout.row,
mCursor,
new …Run Code Online (Sandbox Code Playgroud) 有很多关于如何使用的问题,CheckedTextView但我无法使其正常工作.
我有一个CursorAdapter与具有可自定义视图CheckedTextView用android:id="@android:id/text1".我使用过,android:id/text1因为有不同的问题提到如果你使用它,你将获得免费的选择模式倍数.
如果我做这样的事情:
final long[] checkedIds = mListView.getCheckedItemIds();
for ( int i = 0 ; i < mListView.getCheckedItemCount() ; i++ ) {
Log.d(TAG, "id checked: " + checkedIds[i]);
}
Run Code Online (Sandbox Code Playgroud)
我得到所有已检查的ID没有问题,但我看不到任何视觉反馈ListView.
换句话说,逻辑很好但是当我点击CheckedTextView绿色勾号没有出现时.
我正在读ListViewsrc代码,我找不到任何引用android:id/text1,让我想知道我是否应该自己处理widget的检查状态.
任何人都可以找到android:id/text1用于检查小部件的位置吗?
由于某种原因,setItemChecked不起作用.有人可以帮我解决问题吗?
String[] str = getResources().getStringArray(R.array.brush_type);
sizeArrayAdapter = new ArrayAdapter<String>(this.getContext(), R.layout.drawing_list_item, str);
listType = SIZE_LIST;
listView.setAdapter(sizeArrayAdapter);
// Populate the listView
listView.setItemChecked(4,true);
Run Code Online (Sandbox Code Playgroud)
这是列表项:
<CheckedTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawingCheckedTextView"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:background="@drawable/list_panel"
android:paddingLeft="6dip"
android:paddingRight="6dip"/>
Run Code Online (Sandbox Code Playgroud)
请帮我.