You have write the above code in Oncreate, it will work for the first time when you enter into screen, later it won't, so you need to Execute the above code when an event triggers so
For individual radio buttons set onClickLister
radiobutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//your code here
}
});
And for the group setOnCheckedChangeListener
like this
grp.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup arg0, int arg1) {
//your code here
}
});
post code inside of the above listeners
You can also use onCheckChangeListener on radiobutton
radiobtn.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// your code here
}
});
Edit:
public class MainActivity extends Activity {
EditText message, password, username; // these are called fields
Context context;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//instantiate like this
username = new EditText(this);
password = (EditText) findViewById(R.id.editText2);
message = (EditText) findViewById(R.id.editText3);
}
}