单选择的ListView定制行布局 [英] Single choice ListView custom Row Layout

查看:109
本文介绍了单选择的ListView定制行布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想做出一种选择的ListView有两个TextViews(一排并排)。

I just want to make a Single Choice ListView with two TextViews (side by side in a row).

其实我希望它让用户根据其大小,价格值选择产品。 这些值示于该ListView的与这两个TextViews重新presenting大小 - 价格值。

Actually I want it to let a user select a Product according to its Size-price values. These values are shown in that ListView with those two TextViews representing Size-Price values.

现在的问题是,我不能让一个选项列表(也出现在它的前面单选按钮)。下面是该行布局我使用它:

The problem is that I am not able to make it a single choice list (also showing a radio Button in front of it). Below is the row layout I am using for it:

<?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"
    android:id="@+id/rowLayout" >
    <TextView
        android:id="@+id/tv_size"
        android:layout_width="180dp"
        android:layout_height="wrap_content"
        android:text="Size"
        android:textSize="15sp" />
    <TextView
        android:id="@+id/tv_price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Price"
        android:textSize="15sp" />
   <RadioButton
        android:id="@+id/radioButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right" />
</LinearLayout>

请告知如何code与Java为。 如果有可能与simple_list_item_2布局又如何?

Please tell how to code with Java for that. If it is possible with simple_list_item_2 layout then how ?

推荐答案

我不知道达能在ListView控件创建单选按钮组,我在做什么。只不过处理的选择在Java中。 例如:

I'm not sure tat we can create radio group in ListView, what i'm doing s simply handle the selections in Java. Example:

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        final ViewHolder holder;

        if (view == null) {
            holder = new ViewHolder();

            view = mInflater.inflate(R.layout.customer_invoice_row, null);

            holder.selectionRB = (RadioButton) view
                    .findViewById(R.id.selectionRB);
            holder.sizeTV = (TextView) view
                    .findViewById(R.id.sizeTV);
            holder.priceTV = (TextView) view
                    .findViewById(R.id.priceTV);

            holder.selectionRB.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    RadioButton rb = (RadioButton) v;
                    if (mSelectedRB != null) {
                        if (!rb.getTag().equals(mSelectedRB.getTag()))
                            mSelectedRB.setChecked(false);

                    }
                    mSelectedRB = rb;

                }
            });

            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }


        holder.position = position;

        holder.selectionRB.setTag(productObj);
        holder.sizeTV.setText(productObj.getSize());
        holder.priceTV.setText(productObj.getPrice());
        return view;
    }

持有人:它可以是一个内部类]

Holder: [it can be a inner class]

class ViewHolder {
        int position;

        RadioButton selectionRB;
        TextView sizeTV;
        TextView priceTV;
    }

和mSelectedRB是你的活动一个全球性的成员。

and mSelectedRB is a global member to your activity.

这篇关于单选择的ListView定制行布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆