Code example for RadioGroup

Methods: findViewByIdindexOfChildclearCheckgetCheckedRadioButtonId

0
		// gridview.setChoiceMode(GridView.CHOICE_MODE_SINGLE); 
		gridview.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View v,
					int position, long id) {
				Log.v(TAG, "Interval Chosen: " + id);
				int radioButtonID = mRadioGroup.getCheckedRadioButtonId();
				View radioButton = mRadioGroup.findViewById(radioButtonID);
				int direction = mRadioGroup.indexOfChild(radioButton);
				Log.v(TAG , "Direction Chosen: " + direction);
 
				 
				if ((id == correctInterval && direction  == correctDirection) ||
						(id == correctInterval && correctInterval == 0)) {
					Toast.makeText(getApplicationContext(), "Correct!",
							Toast.LENGTH_SHORT).show();
					numCorrect++;
				} else { 
					Toast.makeText(getApplicationContext(), "Wrong!",
							Toast.LENGTH_SHORT).show();
					numWrong++;
				} 
				mRadioGroup.clearCheck();
				mCountDownTimer.cancel();
				timerRunning = false;
				mCountdown.setText("" + 5);
				mNumCorrect.setText("" + numCorrect);
				mNumWrong.setText("" + numWrong);
Stop searching for code, let great code find you!  Add Codota to your java IDE