2017-07-04 20 views
0

アンドロイドフラグメントで働いていない、私はそれは、正常に動作します私はフラグメントに変換しながら、それは何の応答が得られませんアクティビティ内でこれを試してみました、私を助けてください、ここに私のコードです。あなたがラジオグループ内のLinearLayoutを追加する場合RADIOGROUP私はアンドロイドの断片に動作しない問題のラジオチェック変更リスナーに直面している

K06_Away.java

public class K06_Away extends Fragment { 

     private View kf06_view; 
     protected Typeface tfLatoBold,tfLatoMedium,tfLatoRegular; 
     private Button button_kf06_back,button_kf06_next; 
     private TextView txtVw_kf06_resident_away; 
     private EditText edTxt_kf06_visiting_lastname; 
     private RadioGroup radioGp_kf06_resident_away; 
     List<RadioButton> radioButtons = new ArrayList<RadioButton>(); 

     public View onCreateView(LayoutInflater inflater, ViewGroup container, 
           Bundle savedInstanceState) { 
      kf06_view = inflater.inflate(R.layout.k06_away, container, false); 

      return kf06_view; 
     } 

     @Override 
     public void onViewCreated(View view, Bundle savedInstanceState) { 
      super.onViewCreated(view, savedInstanceState); 
        configViews(); 
     } 


     private void configViews() { 
      button_kf06_back = (Button) kf06_view.findViewById(R.id.button_kf06_back); 
      button_kf06_next = (Button) kf06_view.findViewById(R.id.button_kf06_next); 
      txtVw_kf06_resident_away= (TextView) kf06_view.findViewById(R.id.txtVw_kf06_resident_away); 

      radioGp_kf06_resident_away = (RadioGroup) kf06_view.findViewById(R.id.radioGp_kf06_resident_away); 
      radioButtons.add((RadioButton)kf06_view.findViewById(R.id.radio_kf06_1_2_hours)); 
      radioButtons.add((RadioButton)kf06_view.findViewById(R.id.radio_kf06_halfday)); 
      radioButtons.add((RadioButton)kf06_view.findViewById(R.id.radio_kf06_allday)); 
      radioButtons.add((RadioButton)kf06_view.findViewById(R.id.radio_kf06_moreday)); 

      configClickListeners(); 
      radioButtonAction(); 



     } 
     private void configClickListeners() { 
      button_kf06_back.setOnClickListener(this); 
      button_kf06_next.setOnClickListener(this); 
     } 
     private void radioButtonAction(){ 
      for (RadioButton button : radioButtons){ 
       button.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){ 
        @Override 
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
         if (isChecked) processRadioButtonClick(buttonView); 
         String radio_Text = buttonView.getText().toString(); 
         int radio_Id = buttonView.getId(); 
         System.out.println("Selected the Radio:"+radio_Text+", Radio-Id:"+radio_Id); 
        } 
       }); 

      } 
     } 

     private void processRadioButtonClick(CompoundButton buttonView){ 
      for (RadioButton button : radioButtons){ 
       if (button != buttonView) button.setChecked(false); 
      } 

     } 

} 

k06_away.xml

<RadioGroup 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/lLayout_kf06_resident_away" 
      android:id="@+id/radioGp_kf06_resident_away"> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="horizontal" 
       android:baselineAligned="false" 
       tools:ignore="UselessParent"> 
       <LinearLayout 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:orientation="vertical" 
        android:layout_marginLeft="150dp" 
        tools:ignore="RtlHardcoded"> 
        <RadioButton 
         android:id="@+id/radio_kf06_1_2_hours" 
         style="@style/radionbutton" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/label_resident_away_hour_1" 
         android:layout_gravity="left" 
         android:checked="false" 
         android:textSize="25sp" 
         android:paddingStart="20dp" 
         android:layout_marginTop="150dp" 
         android:textColor="@color/colorWhite" 
         tools:ignore="NestedWeights,RtlSymmetry" /> 

        <RadioButton 
         android:id="@+id/radio_kf06_halfday" 
         style="@style/radionbutton" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/label_resident_away_hour_2" 
         android:layout_gravity="left" 
         android:checked="false" 
         android:textSize="25sp" 
         android:textColor="@color/colorWhite" 
         android:paddingStart="20dp" 
         android:layout_marginTop="50dp" 
         tools:ignore="NestedWeights,RtlSymmetry"/> 


       </LinearLayout> 

       <LinearLayout 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:orientation="vertical" 
        android:layout_marginLeft="50dp" 
        tools:ignore="RtlHardcoded"> 
        <RadioButton 
         android:id="@+id/radio_kf06_allday" 
         style="@style/radionbutton" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/label_resident_away_hour_3" 
         android:layout_gravity="left" 
         android:checked="false" 
         android:textSize="25sp" 
         android:textColor="@color/colorWhite" 
         android:paddingStart="20dp" 
         android:layout_marginTop="150dp" 
         tools:ignore="NestedWeights,RtlSymmetry"/> 

        <RadioButton 
         android:id="@+id/radio_kf06_moreday" 
         style="@style/radionbutton" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/label_resident_away_hour_4" 
         android:layout_gravity="left" 
         android:checked="false" 
         android:textSize="25sp" 
         android:textColor="@color/colorWhite" 
         android:paddingStart="20dp" 
         android:layout_marginTop="50dp" 
         tools:ignore="NestedWeights,RtlSymmetry,RtlHardcoded"/> 


       </LinearLayout> 
      </LinearLayout> 
     </RadioGroup> 
+1

onCreateView 'であなたの' configViews() 'メソッドを呼び出す()'タブレット10インチのタブレット画面用 – tahsinRupam

答えて

1

1.onCreateView()からメソッドconfigViews()を呼び出し、パラメータとしてビューkf06_viewを渡すようにしてください。

2.button_kf06_backbutton_kf06_nextクリックイベントを処理するためにView.OnClickListenerを実装します。以下のように

更新しますK06_Awayフラグメントを:

public class K06_Away extends Fragment implements View.OnClickListener { 

    protected Typeface tfLatoBold,tfLatoMedium,tfLatoRegular; 
    private Button button_kf06_back,button_kf06_next; 
    private TextView txtVw_kf06_resident_away; 
    private EditText edTxt_kf06_visiting_lastname; 
    private RadioGroup radioGp_kf06_resident_away; 
    List<RadioButton> radioButtons = new ArrayList<RadioButton>(); 

    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     View kf06_view = inflater.inflate(R.layout.k06_away, container, false); 

     // Init 
     configViews(kf06_view); 

     return kf06_view; 
    } 

    private void configViews(View view) { 
     button_kf06_back = (Button) view.findViewById(R.id.button_kf06_back); 
     button_kf06_next = (Button) view.findViewById(R.id.button_kf06_next); 
     txtVw_kf06_resident_away= (TextView) view.findViewById(R.id.txtVw_kf06_resident_away); 

     radioGp_kf06_resident_away = (RadioGroup) view.findViewById(R.id.radioGp_kf06_resident_away); 
     radioButtons.add((RadioButton) view.findViewById(R.id.radio_kf06_1_2_hours)); 
     radioButtons.add((RadioButton) view.findViewById(R.id.radio_kf06_halfday)); 
     radioButtons.add((RadioButton) view.findViewById(R.id.radio_kf06_allday)); 
     radioButtons.add((RadioButton) view.findViewById(R.id.radio_kf06_moreday)); 

     configClickListeners(); 
     radioButtonAction(); 
    } 

    @Override 
    public void onClick(View v) { 
     switch (v.getId()) { 
      case R.id.button_kf06_back: 
       // Do something... 
       break; 
      case R.id.button_kf06_next: 
       // Do something... 
       break; 
     } 
    } 

    private void configClickListeners() { 
     button_kf06_back.setOnClickListener(this); 
     button_kf06_next.setOnClickListener(this); 
    } 

    private void radioButtonAction(){ 
     for (RadioButton button : radioButtons){ 
      button.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){ 
       @Override 
       public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
        if (isChecked) processRadioButtonClick(buttonView); 
        String radio_Text = buttonView.getText().toString(); 
        int radio_Id = buttonView.getId(); 
        System.out.println("Selected the Radio:"+radio_Text+", Radio-Id:"+radio_Id); 
       } 
      }); 
     } 
    } 

    private void processRadioButtonClick(CompoundButton buttonView){ 
     for (RadioButton button : radioButtons){ 
      if (button != buttonView) button.setChecked(false); 
     } 
    } 
} 
+0

ちょっとFAT、私は私の質問のための解決策を得た、実際の理由は私の背景の画面の色とアクセントの色は同じですので、ビューは選択を表示することができませんでした。努力していただきありがとうございます、脳が衰えてしまいました。 –

+0

大歓迎です。ハッピーコーディング:) – FAT

1

RADIOGROUPは直接work.Directly、それを唯一のラジオボタンは、他のレイアウトを含んでいませんLinearLayoutを使用してRadiogroupのRadiobuttonを追加してください。

+0

私の設計要件。この設計を除いて私の側で行う他の可能性。 –

+0

各RadioButtonクリックリストを追加してから、このクリックリストを使用して、他のRadioButtonの設定を解除し、RadioButtonをクリックしました。 –

関連する問題