2017-04-05 30 views
0

私のコードでエラーを見つけようとしています。なぜ私のアプリがクラッシュするのか分かりません。ラジオボタンのクリック数をユーザーごとに追加しようとしています。しかし、送信ボタンをクリックすると、私のアプリケーションは残念ながら停止しました。ラジオボタンをラジオグループ内で1回だけクリックできますが、私の場合、すべてのボタンをクリックすることができます。みんな助けてくれますか?ラジオボタンのフロート値を一緒に追加するには?

p/s私はまだこのことで新しいので、私のコーディングを笑わないでください。私は本当にどこから始めるべきか分かりません.2週間ほど経っていますので、これについてのフィードバックをいただければ大変ありがたいです。ここで

は私のxml

<TextView android:id="@+id/tv2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:fontFamily="serif" android:paddingTop="10dp" android:text=" 1. INTRODUCTION (Problem statement, research 
       objectives, research questions, hypothesis, limitation of the 
        study, significance of the study)" android:textAppearance="@style/TextAppearance.AppCompat" /> 

<RadioGroup android:id="@+id/rg1" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="10dp"> 

    <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> 

    <RadioButton android:id="@+id/rb1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:checked="false" android:text="@string/_1" /> 

    <RadioButton android:id="@+id/rb2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:checked="false" android:text="@string/_2" /> 

    <RadioButton android:id="@+id/rb3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:checked="false" android:text="@string/_3" /> 

    <RadioButton android:id="@+id/rb4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:checked="false" android:text="@string/_4" /> 

    <RadioButton android:id="@+id/rb5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:checked="false" android:text="@string/_5" /> 
    </LinearLayout> 
</RadioGroup> 

</LinearLayout> 

<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="10dp" android:orientation="vertical"> 

    <TextView android:id="@+id/tv3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:fontFamily="serif" android:paddingTop="10dp" android:text=" 2. LITERATURE REVIEW (Relevant literature)" android:textAppearance="@style/TextAppearance.AppCompat" 
    /> 

    <RadioGroup android:id="@+id/rg2" android:layout_width="match_parent" android:layout_height="match_parent"> 

    <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:paddingTop="10dp"> 

     <RadioButton android:id="@+id/rb6" style="@style/Widget.AppCompat.CompoundButton.RadioButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="1" /> 

     <RadioButton android:id="@+id/rb7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="2" /> 

     <RadioButton android:id="@+id/rb8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="3" /> 

     <RadioButton android:id="@+id/rb9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="4" /> 

     <RadioButton android:id="@+id/rb10" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="5" /> 
    </LinearLayout> 
    </RadioGroup> 
</LinearLayout> 

<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="10dp" android:orientation="vertical"> 


    <TextView android:id="@+id/tv4" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:fontFamily="serif" android:paddingTop="10dp" android:text=" 3. RESEARCH METHODOLOGY (Research design, research context, data collection, data analysis)" 
    android:textAppearance="@style/TextAppearance.AppCompat" /> 

    <RadioGroup android:id="@+id/rg3" android:layout_width="match_parent" android:layout_height="match_parent"> 

    <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:paddingTop="10dp"> 

     <RadioButton android:id="@+id/rb11" style="@android:style/Widget.CompoundButton.RadioButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="1" /> 

     <RadioButton android:id="@+id/rb12" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="2" /> 

     <RadioButton android:id="@+id/rb13" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="3" /> 

     <RadioButton android:id="@+id/rb14" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="4" /> 

     <RadioButton android:id="@+id/rb15" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="5" /> 
    </LinearLayout> 
    </RadioGroup> 
</LinearLayout> 

<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> 

    <TextView android:id="@+id/tv5" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:fontFamily="serif" android:paddingTop="10dp" android:text=" 4. RESULT AND FEASIBILITY OF STUDY (Justification of the result, implication of the study, recommendation for future research" 
    android:textAppearance="@style/TextAppearance.AppCompat" /> 

    <RadioGroup android:id="@+id/rg4" android:layout_width="match_parent" android:layout_height="match_parent"> 

    <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:paddingTop="10dp"> 

     <RadioButton android:id="@+id/rb16" style="@android:style/Widget.DeviceDefault.CompoundButton.RadioButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="1" /> 

     <RadioButton android:id="@+id/rb17" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="2" /> 

     <RadioButton android:id="@+id/rb18" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="3" /> 

     <RadioButton android:id="@+id/rb19" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="4" /> 

     <RadioButton android:id="@+id/rb20" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="5" /> 
    </LinearLayout> 
    </RadioGroup> 
</LinearLayout> 

<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> 

    <TextView android:id="@+id/tv6" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:fontFamily="serif" android:paddingTop="10dp" android:text=" 5. POSTER PRESENTATION (Type size and type face are easily read, aesthetically pleasing layout, appropriate pictures, and colour is strategically used)" 
    android:textAppearance="@style/TextAppearance.AppCompat" /> 

    <RadioGroup android:id="@+id/rg5" android:layout_width="match_parent" android:layout_height="match_parent"> 

    <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:paddingTop="10dp"> 

     <RadioButton android:id="@+id/rb21" style="@android:style/Widget.DeviceDefault.Light.CompoundButton.RadioButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="1" /> 

     <RadioButton android:id="@+id/rb22" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="2" /> 

     <RadioButton android:id="@+id/rb23" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="3" /> 

     <RadioButton android:id="@+id/rb24" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="4" /> 

     <RadioButton android:id="@+id/rb25" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="5" /> 
    </LinearLayout> 
    </RadioGroup> 
</LinearLayout> 

<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> 

    <TextView android:id="@+id/tv7" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:fontFamily="serif" android:paddingTop="10dp" android:text=" 6. PRESENTATION SKILLS (Smooth transition, eye contact, voice and pacing, enthusiasm, body language)" 
    android:textAppearance="@style/TextAppearance.AppCompat" /> 

    <RadioGroup android:id="@+id/rg6" android:layout_width="match_parent" android:layout_height="match_parent"> 

    <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal" android:paddingTop="10dp"> 

     <RadioButton android:id="@+id/rb26" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="1" /> 

     <RadioButton android:id="@+id/rb27" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="2" /> 

     <RadioButton android:id="@+id/rb28" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="3" /> 

     <RadioButton android:id="@+id/rb29" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="4" /> 

     <RadioButton android:id="@+id/rb30" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="5" /> 
    </LinearLayout> 

    </RadioGroup> 
</LinearLayout> 

<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> 

    <TextView android:id="@+id/tv8" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:fontFamily="serif" android:paddingTop="10dp" android:text=" 7. CONCLUSION (End argument, defend the research, able to answer questions based on research)" 
    android:textAppearance="@style/TextAppearance.AppCompat" /> 

    <RadioGroup android:id="@+id/rg7" android:layout_width="match_parent" android:layout_height="match_parent"> 

    <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal" android:paddingTop="10dp"> 

     <RadioButton android:id="@+id/rb31" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="1" /> 

     <RadioButton android:id="@+id/rb32" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="2" /> 

     <RadioButton android:id="@+id/rb33" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="3" /> 

     <RadioButton android:id="@+id/rb34" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="4" /> 

     <RadioButton android:id="@+id/rb35" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="5" /> 
    </LinearLayout> 

    </RadioGroup> 
</LinearLayout> 

<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="10dp" android:orientation="vertical" android:weightSum="1"> 

    <TextView android:id="@+id/tv_comment" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:fontFamily="serif" android:paddingBottom="10dp" android:paddingTop="10dp" android:text="Comment" android:textAppearance="@style/TextAppearance.AppCompat" 
    android:textSize="18sp" android:textStyle="bold" /> 

    <EditText android:id="@+id/et_comment" android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginTop="10dp" android:ems="10" android:fontFamily="serif" android:gravity="top" android:inputType="textMultiLine" android:lines="5" 
    android:paddingTop="20dp" android:text="Please Enter Your Comment Here" android:layout_weight="0.85" /> 
</LinearLayout> 

<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> 

    <Button android:id="@+id/btn_submit" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Submit" /> 
</LinearLayout> 

<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> 

    <TextView android:id="@+id/tv_outcome" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" /> 
</LinearLayout> 
</LinearLayout> 
</LinearLayout> 
</ScrollView> 

、ここでは私はあなたがRadioGroupLinearLayoutを使用する必要はありません

package com.example.posterevaluation; 

import android.support.v7.app.AppCompatActivity; 

import android.os.Bundle; 

import android.view.View; 

import android.widget.RadioButton; 

import android.widget.RadioGroup; 

import android.widget.Button; 

import android.widget.TextView; 


public class FormActivity extends AppCompatActivity { 

//RadioGroup rg1,rg2,rg3,rg4,rg5,rg6,rg7; 
// RadioButton rb1, rb2,rb3,rb4,rb5,rb6,rb7; 
// EditText et1; 
Button btn_submit; 
TextView tv_outcome; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_form); 

    final RadioGroup rg1 = (RadioGroup) findViewById(R.id.rg1); 
    final RadioGroup rg2 = (RadioGroup) findViewById(R.id.rg2); 
    final RadioGroup rg3 = (RadioGroup) findViewById(R.id.rg3); 
    final RadioGroup rg4 = (RadioGroup) findViewById(R.id.rg4); 
    final RadioGroup rg5 = (RadioGroup) findViewById(R.id.rg5); 
    final RadioGroup rg6 = (RadioGroup) findViewById(R.id.rg6); 
    final RadioGroup rg7 = (RadioGroup) findViewById(R.id.rg7); 
    //et1 = (EditText) findViewById (R.id.et1); 

    tv_outcome = (TextView) findViewById(R.id.tv_outcome); 

    btn_submit = (Button) findViewById(R.id.btn_submit); 


    btn_submit.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 

      String value1 = ((RadioButton) findViewById(rg1.getCheckedRadioButtonId())).getText().toString(); 
      String value2 = ((RadioButton) findViewById(rg2.getCheckedRadioButtonId())).getText().toString(); 
      String value3 = ((RadioButton) findViewById(rg3.getCheckedRadioButtonId())).getText().toString(); 
      String value4 = ((RadioButton) findViewById(rg4.getCheckedRadioButtonId())).getText().toString(); 
      String value5 = ((RadioButton) findViewById(rg5.getCheckedRadioButtonId())).getText().toString(); 
      String value6 = ((RadioButton) findViewById(rg6.getCheckedRadioButtonId())).getText().toString(); 
      String value7 = ((RadioButton) findViewById(rg7.getCheckedRadioButtonId())).getText().toString(); 


      float marks = Float.parseFloat(value1 + value2 + value3 + value4 + value5 + value6 + value7); 

      //calculate total 

      float total = makeCalculations(marks); 

      tv_outcome.setText(String.valueOf(total)); 

     } 
    }); 

} 

private float makeCalculations(float marks) { 

    return ((marks/35) * 100); 

} 
} 
+0

float marks = Float.parseFloat(value1) + Float.parseFloat(value2) + Float.parseFloat(value3) + Float.parseFloat(value4) + Float.parseFloat(value5) + Float.parseFloat(value6) + Float.parseFloat(value7); 

をお試しください) –

+0

if(rg.isChecked())if値に設定します。その後、追加します。 –

+0

ラジオグループごとにコーディングする必要がありますか? – lyle

答えて

1

あなたのXMLのjavaファイルはここに掲載されているが、我々はあまりにも、あなたのログを持っていた場合、それはより有用されていると思います。だから、次回はあなたのログを忘れないでください。みんなのリクエストとして

、あなたはラジオボタンは一度クリックし、このようにラインでこれらのラジオボタンをしたい場合horizontalRadioGroupの向きを設定する場合は、すべての最初は、RadioGroupからLinearLayoutを削除します。

<RadioGroup 
    android:id="@+id/rg1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <RadioButton 
    android:id="@+id/rb1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/_1" /> 

    <RadioButton 
    android:id="@+id/rb2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/_2" /> 

    <RadioButton 
    android:id="@+id/rb3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/_3" /> 

    <RadioButton 
    android:id="@+id/rb4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/_4" /> 

    <RadioButton 
    android:id="@+id/rb5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/_5" /> 
</RadioGroup> 

ここではログがないので、これはあなたのコードが私にとって奇妙に見える場所です。この[解答](http://stackoverflow.com/questions/11194515/android-get-value-of-the-selected-radio-buttonをご確認ください>代わりに

float marks = Float.parseFloat(value1 + value2 + value3 + value4 + value5 + value6 + value7); 
+0

ああ私の神。どうもありがとうございます!それは働く..もし私がこれが起こることを知ったら2週間前に尋ねるだろう... tqvm !! – lyle

+0

これは問題だった。ウェルカム&ハッピーコーディング。 – Journey

1

コーディングされています。 RadioGroupの向きを設定し、RadioButtonRadioGroupのすぐ内側に置きます。

<RadioGroup 
    android:id="@+id/rg1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:paddingTop="10dp"> 

    <RadioButton 
     android:id="@+id/rb1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:checked="false" 

     android:text="@string/_1" /> 

    <RadioButton 
     android:id="@+id/rb2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:checked="false" 

     android:text="@string/_2" /> 

    <RadioButton 
     android:id="@+id/rb3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 

     android:checked="false" 

     android:text="@string/_3" /> 

    <RadioButton 
     android:id="@+id/rb4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:checked="false" 

     android:text="@string/_4" /> 

    <RadioButton 
     android:id="@+id/rb5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:checked="false" 

     android:text="@string/_5" /> 
</RadioGroup> 
+0

私は水平線にしたい。私もscrollviewを使用しました。線形レイアウトを削除するとエラーになる – lyle

+0

'RadioGroup'の向きを水平に設定できます。 'RadioGroup'内の' LinearLayout'を削除してください。 – Deena

+0

ありがとうございます。それは助けますが、計算に何か問題があります。私がラジオボタン "5"を押すと100%になると思います。しかしそれは1.5873014E7になった。私の計算部分を見てくださいできますか? – lyle

1

RadioButtonはRadioGroupの直接の子である必要があります。それ以外の場合、グループ化は機能しません。例えば

<RadioGroup android:id="@+id/rg4" android:layout_width="match_parent" android:layout_height="match_parent"> 

    <RadioButton android:id="@+id/rb16" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="1" /> 

    <RadioButton android:id="@+id/rb17" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="2" /> 

    <RadioButton android:id="@+id/rb18" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="3" /> 

    <RadioButton android:id="@+id/rb19" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="4" /> 

    <RadioButton android:id="@+id/rb20" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="5" /> 
</RadioGroup> 
関連する問題