【发布时间】:2015-06-16 14:11:14
【问题描述】:
我是 Android 编程新手,因此我们将不胜感激!我有一个如图所示的 ListActivity:
public class BasicViews5Activity extends ListActivity {
String[] names;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListView listView = getListView();
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setTextFilterEnabled(true);
names = getResources().getStringArray(R.array.names_array);
setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_checked,names));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Toast.makeText(this,"You have selected " + names[position], Toast.LENGTH_SHORT).show();
}
}
如何更改 ListView 中 CheckBox 的可绘制对象?
我的 Xml 看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button android:id="@+id/btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Show selected items"
android:onClick="onClick"/>
<ListView
android:id="@+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/checked"/>
</LinearLayout>
【问题讨论】:
-
你指的是图标吗?选中/未选中
-
是的图标,选中/取消选中。