2016-03-31 13 views
0

ラジオボタンがチェックされているかどうかをチェックしたい。しかし、断片の中でこれは動作していない私は理由のために把握することはできません?誰かがそれを非常に感謝するのを助けることができるならば!ラジオボタンフラグメント内でsetOnChangeListenerが機能しない

マイフラグメント:

public class OneFragment extends Fragment { 

RadioGroup radioFanStatus; 
RadioButton radioButtonOn; 
RadioButton radioButtonOff; 
View inflateView; 
TabDisplay tabDisplay; 
public OneFragment() 
{ 
    // Required empty public constructor 
} 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Inflate the layout for this fragment 
    inflateView=inflater.inflate(R.layout.fragment_one, container, false); 

    radioFanStatus = (RadioGroup)inflateView.findViewById(R.id.radioOnOff); 
    radioButtonOn=(RadioButton)inflateView.findViewById(R.id.radioFanOn); 
    radioButtonOff=(RadioButton)inflateView.findViewById(R.id.radioFanOff); 


     radioFanStatus.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() 
     { 

     @Override 
     public void onCheckedChanged(RadioGroup group, int checkedId) { 
      Toast.makeText(getContext(),"On",Toast.LENGTH_SHORT).show(); 

     // Log.e("",""+checkedId); 
      Toast.makeText(getContext(),"On"+checkedId+"",Toast.LENGTH_SHORT).show(); 

      // checkedId is the RadioButton selected 
      if(checkedId ==R.id.radioFanOn) 
      { 
       Toast.makeText(getContext(),"On"+checkedId+"",Toast.LENGTH_SHORT).show(); 
       ((TabDisplay)getActivity()).functionFanOn(); 
       Log.e("","on"); 
      } 
      else if(checkedId ==R.id.radioFanOff) 
      { 
       Toast.makeText(getContext(),"Off"+checkedId+"",Toast.LENGTH_SHORT).show(); 
       ((TabDisplay)getActivity()).functionFanOff(); 
       Log.e("","off"); 
      } 
      else 
      { 

      } 
     } 
    }); 
    return inflater.inflate(R.layout.fragment_one, container, false); 
} 

} 

これは、フラグメントに関連する私のxmlです:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" > 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Change staus" 
    android:textSize="40dp" 
    android:layout_centerInParent="true"/> 

<RadioGroup 
    android:id="@+id/radioOnOff" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <RadioButton 
     android:id="@+id/radioFanOn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="On" 
     /> 

    <RadioButton 
     android:id="@+id/radioFanOff" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Off" /> 


</RadioGroup> 

+0

正確には機能しないものはありますか?何か間違いはありますか?何を修正しようとしましたか?このページの指示に従って、質の高い質問を作成してください:http://stackoverflow.com/help/how-to-ask –

答えて

1

return inflater.inflate(R.layout.fragment_one, container, false); 

を変更しよう

return inflateView; 

これでレイアウトを2倍に膨張させました。

+0

はい!これは働いた!!本当にありがとう、私はこれを行うために多くの時間を無駄にしました。もう一度あなたに感謝します。 –

+0

あなたは大歓迎です。役に立った場合は、その答えを受け入れてください –

関連する問題