2017-09-12 4 views
1

シンプルなコードが貼り付けられています。 Radiobuttonがチェックされていることを確認してから、Buttonをクリックしてみてください。男性のラジオボタンをクリックすると、結果は完全に表示されますが、女性のラジオボタンをチェックしても何も表示されない場合や、エラーが表示されない場合もあります。私は自分のコードで何が間違っているのか分かりません。見てみてください:ここではラジオボタンがボタンで機能しない場合は、アンドロイドでクリックしてください。

RadioButton radm,radf; 
radm=(RadioButton)findViewById(R.id.radiomale); 
radf=(RadioButton)findViewById(R.id.radiofemale); 
Button find=(Button) findViewById(R.id.btnfind); 

//Where s is Spinner and find is Button 

    find.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

if(s.getSelectedItem().toString().equals("KG")){ 

        if(radm.isChecked()){ 


         int inches= myfoot*12+myinch; 

         float sizeincm= inches*2.54f; 
         mybmr= (float) (66.47f+ (13.7*myweight) +(5*sizeincm) -6.8 * myage); 
         myrmr= (float) ((10*myweight)+(6.25*sizeincm)-(5*myage)+5); 
         mygcal=level.getSelectedItem().toString(); 

         Intent intent = new Intent(MainActivity.this, Output_activity.class); 
         Bundle extras = new Bundle(); 

         extras.putFloat("bmr",mybmr); 
         extras.putFloat("rmr",myrmr); 
         extras.putString("gcal",mygcal); 
         intent.putExtras(extras); 
         startActivity(intent); 


        } 
       } 



        else if(s.getSelectedItem().toString().equals("KG")){ 
        if(radf.isChecked()) { 

          int inches = myfoot * 12 + myinch; 

          float sizeincm = inches * 2.54f; 
          mybmr = (float) (655.1f + (9.6 * myweight) + (1.8 * sizeincm) - 4.7 * myage); 
          myrmr = (float) ((10 * myweight) + (6.25 * sizeincm) - (5 * myage) + 5); 
          mygcal = level.getSelectedItem().toString(); 

          Intent intent = new Intent(MainActivity.this, Output_activity.class); 
          Bundle extras = new Bundle(); 

          extras.putFloat("bmr", mybmr); 
          extras.putFloat("rmr", myrmr); 
          extras.putString("gcal", mygcal); 
          intent.putExtras(extras); 
          startActivity(intent); 


         } 
       } 
    } 
    }); 

は私のXMLです:このように

<RadioGroup 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/radmf" 
     android:padding="4dp" 
     android:orientation="vertical"> 

     <RadioButton 
      android:layout_width="match_parent" 
      android:layout_height="45dp" 
      android:text="Male" 
      android:checked="true" 
      android:background="@drawable/customedittext" 
      android:id="@+id/radiomale"/> 
     <View 
      android:layout_width="match_parent" 
      android:layout_height="5dp"/> 


     <RadioButton 
      android:layout_width="match_parent" 
      android:layout_height="45dp" 
      android:text="Female" 
      android:background="@drawable/customedittext" 
      android:id="@+id/radiofemale"/> 


    </RadioGroup> 
+0

デバッグを試して、あなたが得た値を参照してください。 –

+0

私は試しましたが、それ以外の場合は2番目に進まない、私は女性のラジオボタンで意味します。 –

+0

if文で行ったのと同じチェックを行っている場合は、他にも同様です。もしあなたの場合は、他からコンテンツを入れてください。 –

答えて

1

私はこのように私の問題を解決した:まだ

if(s.getSelectedItem().toString().equals("KG") && radm.isChecked()){ 




         int inches= myfoot*12+myinch; 

         float sizeincm= inches*2.54f; 
         mybmr= (float) (66.47f+ (13.7*myweight) +(5*sizeincm) -6.8 * myage); 
         myrmr= (float) ((10*myweight)+(6.25*sizeincm)-(5*myage)+5); 
         mygcal=level.getSelectedItem().toString(); 

         Intent intent = new Intent(MainActivity.this, Output_activity.class); 
         Bundle extras = new Bundle(); 

         extras.putFloat("bmr",mybmr); 
         extras.putFloat("rmr",myrmr); 
         extras.putString("gcal",mygcal); 
         intent.putExtras(extras); 
         startActivity(intent); 


       } 



        else if(s.getSelectedItem().toString().equals("KG") && radf.isChecked()){ 



          int inches = myfoot * 12 + myinch; 

          float sizeincm = inches * 2.54f; 
          mybmr = (float) (655.1f + (9.6 * myweight) + (1.8 * sizeincm) - 4.7 * myage); 
          myrmr = (float) ((10 * myweight) + (6.25 * sizeincm) - (5 * myage) + 5); 
          mygcal = level.getSelectedItem().toString(); 

          Intent intent = new Intent(MainActivity.this, Output_activity.class); 
          Bundle extras = new Bundle(); 

          extras.putFloat("bmr", mybmr); 
          extras.putFloat("rmr", myrmr); 
          extras.putString("gcal", mygcal); 
          intent.putExtras(extras); 
          startActivity(intent); 



       } 

感謝あなたの時間のためにアンダースに。ありがとう

+0

np、あなたはそれを固定してうれしい –

+0

:)祝福されて –

0

RadioButton radm,radf; 
radm=(RadioButton)findViewById(R.id.radiomale); 
radf=(RadioButton)findViewById(R.id.radiofemale); 
Button find=(Button) findViewById(R.id.btnfind); 

//Where s is Spinner and find is Button 

find.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     if(s.getSelectedItem().toString().equals("KG")){ 

      if(radm.isChecked()){ 
       int inches= myfoot*12+myinch; 

       float sizeincm= inches*2.54f; 
       mybmr= (float) (66.47f+ (13.7*myweight) +(5*sizeincm) -6.8 * myage); 
       myrmr= (float) ((10*myweight)+(6.25*sizeincm)-(5*myage)+5); 
       mygcal=level.getSelectedItem().toString(); 

       Intent intent = new Intent(MainActivity.this, Output_activity.class); 
       Bundle extras = new Bundle(); 

       extras.putFloat("bmr",mybmr); 
       extras.putFloat("rmr",myrmr); 
       extras.putString("gcal",mygcal); 
       intent.putExtras(extras); 
       startActivity(intent); 


      }else if (radf.isChecked()){ 
        int inches = myfoot * 12 + myinch; 

        float sizeincm = inches * 2.54f; 
        mybmr = (float) (655.1f + (9.6 * myweight) + (1.8 * sizeincm) - 4.7 * myage); 
        myrmr = (float) ((10 * myweight) + (6.25 * sizeincm) - (5 * myage) + 5); 
        mygcal = level.getSelectedItem().toString(); 

        Intent intent = new Intent(MainActivity.this, Output_activity.class); 
        Bundle extras = new Bundle(); 

        extras.putFloat("bmr", mybmr); 
        extras.putFloat("rmr", myrmr); 
        extras.putString("gcal", mygcal); 
        intent.putExtras(extras); 
        startActivity(intent); 
      } 
     } 
    } 
}); 
+0

アンダーさんにお試しください! –

+0

いいえ..私はあなたが答える前にこれも試しました..しかし、これはうまくいきません! –

関連する問題