シンプルなコードが貼り付けられています。 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>
デバッグを試して、あなたが得た値を参照してください。 –
私は試しましたが、それ以外の場合は2番目に進まない、私は女性のラジオボタンで意味します。 –
if文で行ったのと同じチェックを行っている場合は、他にも同様です。もしあなたの場合は、他からコンテンツを入れてください。 –