Android如何使用checkedtextview [英] Android how to use checkedtextview

查看:92
本文介绍了Android如何使用checkedtextview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题不言而喻.我浏览了几篇文章,主题,但仍然没有弄清楚如何使用checkedtextview.我想要带有可检查项目的列表视图.在下面的代码中,我正在使用列表视图,并使用字符串数组填充它.但是如何将其更改为checkedtextview?

the title speaks for itself. I am over several articles, topics and still haven't figured out how to use checkedtextview. I want a listview with checkable items. In the following code i am using a listview and populating it with a string array. But how to change it to checkedtextview?

delete.xml:

delete.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>

delete_lv.xml:

delete_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>

Delete.java:

Delete.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();

}
}

推荐答案

在您的xml文件中,您正在使用textview作为列表项.而不是使用 CheckedTextView .您可以将其直接从窗口小部件面板中拖放.您可以将 CheckedTextView 用作 TextView CheckBox .下面是一个如何使用它的示例

In your xml file you're using textview as list item. Instead of that use CheckedTextView. You can directly drag and drop that from your widgets palette. You can use the CheckedTextView as both TextView and CheckBox. Below is an example if how to use it

   <CheckedTextView 
      xmlns:android="http://schemas.android.com/apk/res/android"     
      style="@style/NormalText"  
      android:id="@+id/checkList" 
      android:paddingLeft="20dip" 
      android:paddingRight="20dip" 
      android:paddingTop="10dip"
      android:paddingBottom="10dip" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="?android:attr/listPreferredItemHeight"  
      android:gravity="center_vertical"  
      android:checkMark="@drawable/our_checkbox"></CheckedTextView>

这篇关于Android如何使用checkedtextview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆