14

タイトルはそれ自体を物語っています。私はいくつかの記事、トピックを読み終えましたが、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>

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>

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

}
}
4

5 に答える 5

17

あなたのxmlファイルでは、テキストビューをリスト項目として使用しています。その代わりにCheckedTextView. ウィジェット パレットから直接ドラッグ アンド ドロップできます。はとのCheckedTextView両方として使用できます。以下は、それを使用する方法の例ですTextViewCheckBox

   <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>
于 2011-05-25T09:03:12.933 に答える
4

android:drawableLeft左側のチェックボックスを設定するために使用できます。それを実現するために、以下のコード スニペットを使用できます。

<CheckedTextView
    android:id="@+id/checkedTextView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/custom_radio_check"
    android:gravity="center_vertical"
    android:textSize="12sp"
    android:textColor="#3d484d"
    android:paddingLeft="14dp"
    android:paddingTop="12dp"
    android:paddingBottom="12dp"
    />

これにより、セレクターがテキストの左側に移動します。パディング、重力などの残りのパラメーターを調整できます。

于 2013-06-07T11:53:21.077 に答える
-1

アダプターのレイアウトに、CheckBox と textview を持つカスタム アダプターを記述できます。次に、リストの setOnItemClick リスナーで複数選択と単一選択を処理します。

詳細については、このリンクを確認できますセレクターを使用せずにListViewの選択したアイテムの色をデフォルトから赤に変更する方法

于 2015-01-08T12:24:38.303 に答える