2013-06-20 2 views
2

약간의 문제가 있습니다. 나는 ListView가 있고 나는 다음을 사용한다 :ListView에서 라디오 버튼의 위치를 ​​변경하십시오.

ArrayAdapter adapter = new ArrayAdapter<String>(this, 
     android.R.layout.simple_list_item_single_choice, 
     data); 

단일 선택 목록을 가지고있다. 하지만이 솔루션에서는 오른쪽에 라디오 버튼이 있지만 왼쪽에 넣고 싶습니다. 어떻게해야합니까?

편집 : 내 XML 파일 :

<LinearLayout  
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:orientation="vertical" 
    android:layout_weight="92.5"> 
    <TextView 
     android:id="@+id/user_account_text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginTop="109dp" 
     android:text="@string/user_account_text" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <ListView 
     android:id="@+id/user_account" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginTop="10dp" 
     android:scrollbars="vertical" 
     android:layout_marginRight="100dp" 
     android:layout_weight="1" 
     android:layout_marginLeft="100dp"> 
    </ListView> 

    <Button 
     android:id="@+id/login_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
     android:layout_marginBottom="20dp" 
     android:layout_gravity="center" 
     android:text="@string/login" 
     android:background="@drawable/button" 
     android:textColor="@android:color/white"/> 

</LinearLayout> 
+1

당신은 사용자 정의 어댑터를 사용하여 레이아웃 XML 파일 – chancea

+1

을 게시하고 사용자 정의 팽창 수 체크 박스 또는 라디오 버튼이있는 레이아웃. 사용자 정의 레이아웃을 정의 할 수 있습니다. – Raghunandan

답변

6

  • 새로운 라인을 추가 android:checkMark="?android:attr/listChoiceIndicatorSingle"android:checkMark="@null"

    1. 변경, 새로운 xml 레이아웃을 만든 다음 android.R.layout.simple_list_item_single_choice (here)

      의 소스 코드를 복사 체크 박스를 원한다면 다음을 사용하십시오 :
      android:drawableLeft="?android:attr/listChoiceIndicatorMultiple"

    2. 를 사용하여 코드에서이 새로운 레이아웃 :
      ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.YOUR_NEW_XML, data);

    이 스레드가 당신을 위해 도움이 될 수 : How do I make the Checkbox in Android CheckedTextView be left aligned instead of right aligned?

  • +0

    위대한 솔루션입니다. 고마워요 :) – edi233

    +0

    당신은 환영합니다 :) – sromku

    1

    , 당신의 간단한 어댑터와 레이아웃

    <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:orientation="horizontal" > 
        <RadioButton 
         android:layout_width="wrap_content" android:id="@+id/radio" 
         android:layout_height="wrap_content" /> 
        <TextView 
         android:layout_width="wrap_content" 
         android:id="@+id/text" 
         android:layout_height="wrap_content" 
         android:text="hi" /> 
    </LinearLayout> 
    

    SimpleAdapter 어댑터 = 새로운 SimpleAdapter (이, 데이터, R.layout.main을 사용하여 new String [] { ""}, 새로운 int [] {R.id.txt});

    list.setAdapter (adapter); android:drawableLeft="?android:attr/listChoiceIndicatorSingle"
    나 같은 경우

    관련 문제