定制单个选择的ListViewListView

2023-09-12 04:08:54 作者:花开花落终无果

我迫切想创建一个自定义列表视图有两个TextViews和单行一个单选按钮。而在列表项单击单选按钮状态应该是切换。我不能在这里使用简单的适配器。

I urgently want to make a custom List View having Two TextViews and a radio Button in a single row. And on listitem click the radio button state should be toggle. I cannot use Simple Adapter here.

我已经问这个问题单选ListView的定制行布局但不找到令人满意的解决方案。所以这一次,我问了一些更多的细节。

I have already asked that question Single choice ListView custom Row Layout but dont find any satisfactory solution. So this time I am asking with some more details.

我目前做的是我使用simple_list_item_single_choice并把两个TextViews的数据在一个单一的一些空格隔开。但在这里它是越来越差(从下面的链接图所示)。

What I am currently doing is I am using simple_list_item_single_choice and putting data of both TextViews in a single one separated by some white spaces. But here it is getting worse(shown in the image from link below).

我要的是解决规模和价格的位置,使列表视图中为单项选择。

What I want is to fix the location of size and price and make list view as single choice.

XML布局的列表可以是这样的: -

XML Layout for the list can be something like :-

**<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/tv_size"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textSize="15sp"
        android:width="200dp" />

    <TextView
        android:id="@+id/tv_price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textSize="15sp"
        android:width="70dp" />

    <RadioButton
        android:id="@+id/radioButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>**

制作自定义适配器为任何帮助将是非常美联社preciated。

Any help for making custom adapter for that will be highly appreciated.

推荐答案

我一个上午都在寻找一个答案,这个问题,而且我迄今为止发现的最有用的东西是的这篇文章。

I've been searching for an answer to this problem all morning, and the most useful thing I've found so far is this article.

虽然我还没有实现它表明还没有解决方案,它听起来就像是在正确的轨道。

While I haven't implemented the solution it suggests yet, it sounds like it's on the right track.

基本上,单项选择题的ListView 期望你为它提供的部件来实现可检查接口。 的LinearLayout 等人没有。所以,你需要创建一个自定义布局继承的LinearLayout (或者你想用你的物品无论布局),并实现必要的接口。

Basically, the single-choice ListView expects the widgets you provide it with to implement the Checkable interface. LinearLayout et al don't. So you need to create a custom layout that inherits LinearLayout (or whatever layout you want to use for your items) and implements the necessary interface.