标题不言自明。我已经阅读了几篇文章,主题,但仍然没有弄清楚如何使用checkedtextview。我想要一个带有可检查项目的列表视图。在下面的代码中,我使用了一个列表视图并用一个字符串数组填充它。但是如何将其更改为checkedtextview?
删除.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/linlay0"
android:background="@color/list_bg">
<TextView
android:id="@+id/TextView00"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#D8D8D8"
android:textColor="#424242"
android:gravity="center_horizontal|center_vertical"
android:textSize="20px"
android:height="40px"
android:textStyle="bold"
/>
<ListView android:id="@+id/ListView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
删除_lv.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/list_content"
android:textColor="#222222"
android:gravity="center"
android:text="sample"
android:layout_margin="4dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
删除.java:
public class Delete extends Activity {
ListView lv1;
ArrayAdapter<String> adapter1;
private String lv_items[] = { "Android", "iPhone", "BlackBerry",
"AndroidPeople", "J2ME", "Listview", "ArrayAdapter", "ListItem",
"Us", "UK", "India" };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.delete);
TextView tv0 = (TextView)findViewById(R.id.TextView00);
tv0.setText("Deletes");
lv1 = (ListView) findViewById(R.id.ListView01);
adapter1 = new ArrayAdapter<String>(Delete.this,R.layout.list_black_text,R.id.list_content, lv_items);
lv1.setAdapter(adapter1);
adapter1.notifyDataSetChanged();
}
}