I am getting this error:
void is an invalid type for the variable onRadioButtonClicked
But the developer site says that void is a must! So where is the problem? The coding of the xml's is correc.. The problem must lie somewhere here:
package com.example.kernel.version;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
public class MainPage extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent=getIntent();
setContentView(R.layout.activity_main_page);
public void onRadioButtonClicked(View view) {
// Is the button now checked?
boolean checked = ((RadioButton) view).isChecked();
// Check which radio button was clicked
switch(view.getId()) {
case R.id.radio_pirates:
if (checked)
// Pirates are the best
break;
case R.id.radio_ninjas:
if (checked)
// Ninjas rule
break;
}
}
Your onRadioButtonClicked
is contained within your onCreate
method—make them separate methods. Add a closing brace }
after:
setContentView(R.layout.activity_main_page);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With