Reputation: 3031
I have a little problem. I have a ListView and I use:
ArrayAdapter adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_single_choice,
data);
to have list with single choice. But in this solution I have a radio buttons on right side, but I want to have them on left side. How can I do that?
Edit: My xml File:
<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>
Upvotes: 2
Views: 1546
Reputation: 2562
Use your simple adapter and your layout
<?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 adapter = new SimpleAdapter(this,data,R.layout.main,new String[]{""},new int[]{R.id.txt});
list.setAdapter(adapter);
Upvotes: 1
Reputation: 4683
Create new xml
layout and copy the source code of android.R.layout.simple_list_item_single_choice
(here)
Then,
android:checkMark="?android:attr/listChoiceIndicatorSingle"
to android:checkMark="@null"
android:drawableLeft="?android:attr/listChoiceIndicatorSingle"
android:drawableLeft="?android:attr/listChoiceIndicatorMultiple"
ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.YOUR_NEW_XML, data);
This thread could be helpful for you: How do I make the Checkbox in Android CheckedTextView be left aligned instead of right aligned?
Upvotes: 9