2016-08-31 2 views
1

カスタムアダプターにはカスタム行がありますが、カスタム行のチェックボックスは表示されません。カスタム行にチェックボックスが表示されない

ここでは、行のXMLコードです:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" 
android:paddingBottom="10dp" 
android:paddingTop="7dp"> 

<android.support.v7.widget.AppCompatCheckBox 
    android:id="@+id/delete_checkbox" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:layout_marginTop="10dp" /> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="3" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/company_symbol" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="@string/unknown" 
     android:textColor="@color/md_grey_600" 
     android:textSize="18dp" /> 

    <TextView 
     android:id="@+id/company_name" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:paddingRight="10dp" 
     android:text="@string/unknown" 
     android:textColor="@color/md_grey_800" 
     android:textSize="12dp" /> 

</LinearLayout> 

私はチェックボックスが行の左側に表示されますが、ここでの結果は次のようになりますことを期待:

Complete ListView

どれでもチェックボックスが表示されない理由についてのヘルプ

+0

同時に重量とラップコンテンツを使用しないでください –

答えて

1

代わりにandroid.support.v7 .widget.AppCompatCheckBox使用のCheckBox

すでにあなたのレイアウトでのCheckBoxを使用する場合は、自動的に使用されますそのドキュメント

で書かれています。カスタムビューを作成する場合は、このクラスを手動で使用する必要があります。

<CheckBox 
    android:id="@+id/delete_checkbox" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:layout_marginTop="10dp" /> 
0

ラップの内容と重量を使用しないでください。ここではandroid:layout_width="0dp"を代わりに使用してください。

<android.support.v7.widget.AppCompatCheckBox 
android:id="@+id/delete_checkbox" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_weight="1" 
android:layout_marginTop="10dp" /> 

<LinearLayout 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_weight="3" 
android:orientation="vertical"> 
0

これを試してください。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" 
android:paddingBottom="10dp" 
android:weightSum="4" 
android:paddingTop="7dp"> 

<android.support.v7.widget.AppCompatCheckBox 
    android:id="@+id/delete_checkbox" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:layout_marginTop="10dp" /> 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="3" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/company_symbol" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="@string/unknown" 
     android:textColor="@color/md_grey_600" 
     android:textSize="18dp" /> 

    <TextView 
     android:id="@+id/company_name" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:paddingRight="10dp" 
     android:text="@string/unknown" 
     android:textColor="@color/md_grey_800" 
     android:textSize="12dp" /> 

     </LinearLayout> 

</LinearLayout> 

希望する場合があります。

関連する問題