2011-11-28 6 views
2

두 개의 TextView (한 행에 나란히 표시)로 단일 선택 목록보기를 만들고 싶습니다.단일 선택 ListView 사용자 정의 행 레이아웃

사실 저는 사용자가 크기 가격 값에 따라 제품을 선택할 수있게하고 싶습니다. 이러한 값은 크기 - 가격 값을 나타내는 두 개의 TextView와 함께 해당 ListView에 표시됩니다.

문제는 단일 선택 목록으로 만들 수 없다는 것입니다 (또한 앞에 라디오 버튼이 있음). 아래는 내가 사용하고있는 행 레이아웃입니다 :

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

시도 에 내가 '무엇의 RadioGroupRadioButtonsRadioGroup.addView()

1

은 우리가 ListView에 라디오 그룹을 만들 수 있습니다 문신 확실하지 않다 사용하여 추가하려면 getView() 또는 bindView()에 다음 어댑터 을 RadioGroup 객체를 선언 m은 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는 액티비티 글로벌 부재이다.

관련 문제