2013-12-21 2 views
0

나는 내 요구에 맞는 다음 link을 보았습니다. 동일한 목록을보기 위해 똑같은 일을하는 데 열심히 노력하고 있습니다. 사람이android : choiceMode = "singleChoice"로 설정하면 라디오 버튼을 볼 수 없습니다

이에 나에게 도움이 되거 수 있기를 바랍니다하면 링크가 무엇 :

android:choiceMode="singleChoice" 세트 listview에 대한 그냥 내가 위의 목록보기 비슷한이 이제 하나의 라디오 버튼을 선택

을 설정 그러나 몇몇 심상 및 textviews 및 아무것도 특별한.

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:background ="#CCCCCC"> 

    <ListView 
     android:id="@+id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:divider="#3366CC" 
     android:dividerHeight="2dp" 
     android:choiceMode="singleChoice"/> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="48dp" 
     android:layout_alignParentBottom="true"> 
     <View 
      android:layout_width="match_parent" 
      android:layout_height="1dip" 
      android:layout_marginLeft="3dip" 
      android:layout_marginRight="3dip" 
      android:background="?android:attr/dividerVertical" 
      android:layout_alignParentTop="true"/> 
     <View 
      android:id="@+id/divider" 
      android:layout_width="1dip" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentBottom="true" 
      android:background="?android:attr/dividerVertical" 
      android:layout_centerHorizontal="true"/> 
     <Button 
      android:id="@+id/btnPrevious" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:layout_toLeftOf="@id/divider" 
      android:background="@drawable/buttons" 
      android:text="Previous" 
      android:layout_alignParentBottom="true" 
      android:textSize="20sp" 
      android:textColor="#4285f4"/> 
     <Button 
      android:id="@+id/btnNext" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:background="@drawable/buttons" 
      android:text="Next" 
      android:layout_alignParentBottom="true" 
      android:layout_toRightOf="@id/divider" 
      android:textSize="20sp" 
      android:textColor="#4285f4"/> 
    </RelativeLayout>   
</LinearLayout> 

지금 내 문제는 내가 위의 링크에서와 같이 그 옆에있는 라디오 버튼을 얻을 수 없습니다 해요입니다 :

여기 내 목록보기입니다.

그리고 여기 내 row.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 
    <ImageView 
     android:id="@+id/photo" 
     android:layout_width="150dip" 
     android:layout_height="100dip" 
     android:paddingRight="15dp" 
     android:paddingLeft="15dp"/> 
    </LinearLayout> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
android:layout_marginLeft="160dp" 
android:layout_marginTop="10dp" 
android:descendantFocusability="blocksDescendants"> 
    <TextView android:id="@+id/name" 
     android:textSize="14sp" 
     android:textStyle="bold" 
     android:textColor="#000000" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
    <TextView android:id="@+id/itemDescription" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/name" 
     android:focusable="false"/> 
    <TextView android:id="@+id/price" 
     android:textSize="19sp" 
     android:textStyle="bold" 
     android:textColor="#003399" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/itemDescription"/> 
</RelativeLayout> 
</RelativeLayout> 

답변

1

당신이 행에 대한 사용 android.R.layout.simple_list_item_single_choice에 연결 샘플입니다. 너는 그렇지 않다. 샘플에 android.R.layout.simple_list_item_single_choicesingleChoiceListView이 사용되어 라디오 버튼이 표시됩니다. singleChoice 만 있으면 라디오 버튼이 추가되지 않습니다.

는 직접 RadioButton를 사용하거나 CheckedTextView를 사용하여 하나의 Checkable 인터페이스를 구현하고 거기에 적절한 라디오 버튼을 가지고 당신의 행에 대한 사용자 정의 View를 작성 (또는 찾기) 할 필요가있다.

예, this blog post shows a CheckedLinearLayout를 들어, 그것은 당신이 singleChoiceListView와 함께 작동하도록 Checkable 인터페이스를 제공하기 위해 공급 장치 A CheckedTextView을 활용합니다.

0

listview의 모든 항목 중에서 하나의 행을 선택하려면 확인란을 사용하지 마십시오. 라디오 버튼 만 사용하십시오. 그것이 사용자 정의 행을 지원하지 않기 때문에 singlechoice listview를 사용하지 마십시오. android.R.layout.simple_list_item_single_choice와 같은 android 기본 레이아웃 만 지원합니다. 그래서 각 열의 라디오 버튼을 사용하여 맞춤 목록 뷰를 만드는 것이 좋습니다. 코드를 통해 단일 선택을 관리하십시오. 나는 이것이 당신을 더 잘 돕는 데 도움이 될 것이라고 생각합니다. 더 많은 도움이 필요하면 pls 말해줘.