2011-11-28 12 views
2

2つのTextView(横並び)を使用して単一選択リストビューを作成したいだけです。単一選択ListViewカスタム行レイアウト

実際には、ユーザーがSize-price値に応じて商品を選択できるようにしたいと考えています。 これらの値は、そのListViewに、Size-Price値を表す2つのTextViewで表示されます。

問題は、単一の選択リストにすることができないということです(また、その前にラジオボタンが表示されています)。以下は、私はそれのために使用していた行のレイアウトです:

<?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> 

そのためのJavaでコーディングする方法を教えてください。 simple_list_item_2レイアウトで可能な場合はどうすればよいですか?

+0

私は同様の質問に答えました:http://stackoverflow.com/questions/8295560/listview-with-checkbox-why-the-checkbox-doesnt-show – QuickNick

答えて

0

私はTATが、我々はi「は何を、リストビューでラジオ・グループを作成することができるかわからない、あなたのアダプタであなたのgetView()で をRadioGroupオブジェクトを宣言したりbindView()RadioGroup.addView()

1

を使用してRadioGroupRadioButtonsを追加 にしてみてください単にJavaで選択を処理するだけです。 例:

@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; 
    } 

ホルダー:[それができる内部クラス]

class ViewHolder { 
     int position; 

     RadioButton selectionRB; 
     TextView sizeTV; 
     TextView priceTV; 
    } 

とmSelectedRBは、あなたの活動にグローバルなメンバーです。

関連する問題