Skip to content

Commit

Permalink
change in layout file
Browse files Browse the repository at this point in the history
Add radiobutton and EditText
dimens files add
strings files add All questions
Add Radio button java code for action and result
  • Loading branch information
tarsbirsingh committed Apr 28, 2018
1 parent db687a3 commit b4aa701
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
18 changes: 16 additions & 2 deletions app/src/main/java/com/example/hp/quiz/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,38 @@
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
private RadioGroup radioGroup1;
RadioButton radioButton1;
int score=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final EditText editName = findViewById(R.id.editText_name);
final TextView displayText = findViewById(R.id.textView_name);
radioGroup1 = findViewById(R.id.radioGroup_Q1);
Button showButton = findViewById(R.id.button_show);

showButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = editName.getText().toString();
displayText.setText(name);

//radio button
int selectedId=radioGroup1.getCheckedRadioButtonId();
radioButton1=findViewById(R.id.radioButton_Q1_op1);
//if statement for radio button
if (selectedId==R.id.radioButton_Q1_op2) {
score +=1;
}
String hell ="Thanks"+name+"your score is"+score;
//display value on screen
displayText.setText(hell);
}
});
}
Expand Down
14 changes: 9 additions & 5 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,43 @@
android:text="@string/Q1"
android:textSize="@dimen/font_size_medium"/>
<RadioGroup
android:id="@+id/rg_Q1"
android:id="@+id/radioGroup_Q1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/oneSix"
android:background="@android:color/holo_orange_light"
android:layout_marginStart="@dimen/oneFour"
android:layout_marginEnd="@dimen/oneFour">
<RadioButton
android:id="@+id/rb_Q1_op1"
android:id="@+id/radioButton_Q1_op1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Q1_Op1"
android:layout_marginTop="@dimen/eight"
android:textSize="@dimen/font_size_medium">
</RadioButton>
<RadioButton
android:id="@+id/rb_Q1_op2"
android:id="@+id/radioButton_Q1_op2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Q1_Op2"
android:layout_marginTop="@dimen/eight"
android:textSize="@dimen/font_size_medium">
</RadioButton>
<RadioButton
android:id="@+id/rb_Q1_op3"
android:id="@+id/radioButton_Q1_op3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/eight"
android:text="@string/Q1_Op3"
android:textSize="@dimen/font_size_medium">
</RadioButton>
<RadioButton
android:id="@+id/rb_Q1_op4"
android:id="@+id/radioButton_Q1_op4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Q1_Op4"
android:layout_marginTop="@dimen/eight"
android:textSize="@dimen/font_size_medium">
</RadioButton>

Expand Down

0 comments on commit b4aa701

Please sign in to comment.