2016-12-22 5 views
0

リストビューに行があります。各列には、同じラジオ・グループの中に2つのラジオ・ボタンがあります。ラジオ・グループのリスト・ビューの各行から1つのラジオ・ボタンを選択してください。

ラジオボタンの名前は「フル」と「パーシャル」です。リストビューのすべての行で「部分」を1つだけ選択し、「フル」にする必要があります。

したがって、ユーザーが1つで「Partial」を選択し、以前にマークされたラジオボタンが「部分的」である場合は、「Full」に変更する必要があります。ここで私は試してみましたが、私が望むように望ましい出力を得られませんでした。

holder.radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() 
      { 
       @Override 
       public void onCheckedChanged(RadioGroup radioGroup, int i) 
       { 
        if(i==R.id.radio_partial_selection) 
        { 
         if (selected != null) 
         { 
          selected.setChecked(false); 
         } 
         holder.radioButton_partial.setChecked(true); 
         Log.d("selected=","11"+selected); 
         selected = holder.radioButton_partial; 
         Log.d("selected=","22"+selected); 
        } 
        if(i==R.id.radio_full_selection) 
        { 

        } 

       } 
      }); 

答えて

0

onCheckedListener以外では、部分ボタンの1つがチェックされたときに切り替わるブール値を設定します。次に、部分スイッチがスローされたかどうかを確認するビューを確認します。表示されている場合は、ビューに部分ボタンの代わりに「フル」ボタンを表示させます。

私はラジオボタンに慣れていないんだものの(私はAndroid上でそれらを使用しhaventは)、 必要であれば、私はあなたのために一緒にサンプルコードのビットを置くことができます。

編集(提供された例コード)あなたの特定の状況で

、これは私があなたの問題を処理する方法をです。コメントの全体を通して述べたように、いくつかの前提があります(私はあなたのコードを持っていないので)

public class sampleRadioButtonActivity extends Activity { 
    /** 
    * When this is set to false, all radio buttons will show partial. 
    * When this is set to true, all radio buttons will show full, except the one that is 
    * set to show partial 
    */ 
    private boolean showPartialOrFull; 

    @Override 
    public void onCreate(Bundle savedInstanceState){ 
     super.onCreate(savedInstanceState); 
     /** 
     * Do your on create stuff here 
     */ 
     /** 
     * We are setting the showPartialOrFull here to be false, 
     * this will allow the view to show partial or full for now 
     */ 
     showPartialOrFull = false; 
     holder.radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(RadioGroup group, int checkedId) { 
       if(checkedId == R.id.radio_partial_selection){ 
        showPartialOrFull = true; 
        changeRadioButtonToFull(holder); 
       } 
      } 
     }); 
    } 

    /** 
    * Because I'm missing some code, assumptions are made here. 
    * The first assumption is that the radio buttons are sitting in a viewgroup. 
    * The second assumption, is more a recommendation, that you put the radiobuttons 
    * in a ViewFlipper or ViewSwitcher (I will be using the first). 
    */ 
    private final void changeRadioButtonToFull(View viewToIgnore){ 
     for(int i = 0; i < viewGroup.getChildCount(); i++){ 
      View child = viewGroup.getChildAt(i); 
      if(child != viewToIgnore){ 
       ((ViewFlipper) child).setDisplayedChild(R.id.radio_full_selection); 
      } 
     } 
    } 
+0

いくつかのサンプルコード – gautam

関連する問題