android listview singlechoice,Android ListView with RadioButton in singleChoice mode and a custom ro...

I have a ListView, which is in single-choice mode. All I want is to display a RadioButton to the side, that when clicked highlights to say it is selected, and when a different one is clicked that one goes back to unselected and the new one becomes selected. Why is this so hard? This should not be this complicated. I've spent DAYS looking for an appropriate answer to this and I have found nothing, so I'm asking hopefully clearly and concisely.

My layout for the listview (R.layout.view_orders):

android:choiceMode="singleChoice"

android:id="@android:id/list"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:divider="@drawable/list_divider"

android:dividerHeight="1px"

android:focusable="false"

android:focusableInTouchMode="false"

android:cacheColorHint="#00000000">

My custom row (R.layout.orders_row):

xmlns:app="http://schemas.android.com/apk/res/com.xxx.xxxxxx"

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:padding="6dip">

app:text="SHORT"

app:textColor="#666"

app:textSize="14sp"

android:id="@+id/state"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_centerVertical="true" />

android:id="@+id/quantity"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_toRightOf="@id/state"

android:layout_centerVertical="true"

android:gravity="center"

android:textSize="40sp"

android:layout_margin="2dip"

android:minWidth="30dip"

android:textColor="#555" />

android:layout_toRightOf="@id/quantity"

android:layout_centerVertical="true"

android:layout_width="fill_parent"

android:layout_height="wrap_content">

android:id="@+id/instrument"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:textSize="20sp"

android:textColor="#333"

android:layout_marginLeft="2dip"

android:layout_marginRight="2dip"

/>

android:id="@+id/deets"

android:layout_below="@id/instrument"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:textSize="16sp"

android:textColor="#888"

android:layout_marginLeft="2dip"

android:layout_marginRight="2dip"

/>

android:id="@+id/selector"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:layout_centerVertical="true"

/>

My onCreate() method:

@Override

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.view_orders);

client = new Client(handler);

ola = new OrdersAdapter(this, R.layout.orders_row, Orders);

setListAdapter(ola);

final RelativeLayout loading = (RelativeLayout) findViewById(R.id.loading);

panel = (PositionsPanel) findViewById(R.id.panel);

Utility.showProgressBar(loading);

client.Connect("orders");

}

Now everything underlying works as expected, you click on a radiobutton, and through its tag, I can appropriately select that item from the list and manipulate it how I want. However, when the first radio button is clicked, the last one will be selected. Click that same radio button again, and it is now selected as well. Click it once more and nothing happens, both the last and the first are selected. Now I click any other one on the list, it gets selected like expected. Click any one of the selected radio buttons and nothing happens, the radio button remains selected.

I have tried using the following in onCreate():

@Override

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.view_orders);

client = new Client(handler);

ola = new OrdersAdapter(this, android.R.layout.simple_list_item_single_choice, Orders);

setListAdapter(ola);

final RelativeLayout loading = (RelativeLayout) findViewById(R.id.loading);

panel = (PositionsPanel) findViewById(R.id.panel);

Utility.showProgressBar(loading);

client.Connect("orders");

}

and that just shows no radio buttons at all. AWESOME.

Now maybe (read: most likely), I'm just dense and can't figure this out, but I've seen this question asked a lot with no real answer. Lots of references to other tutorials or the Commonsware guy's book. However, the comments are old now and his repository has changed so much, that those are no longer correct answers.

So, does anyone have any idea how to get the expected functionality out of this? Or failing that, just pass me along with the Gmail app's source code. :)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值