I am trying to make a simple text game but I cant even get through the first step. There is a textview in the layout and 3 radio buttons. I want to change the text when you click at one of the radio buttons and to determine what text the app is going to use, I have a position int. example: I select button one: if position = 1, then set set text to text 2. If position = 9, then set text to 11 and so on. here is the code:
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
public class Game extends Activity implements OnCheckedChangeListener{
public int position;
TextView text;
RadioGroup rggr;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
position = 1;
text = (TextView) findViewById(R.id.text);
setContentView(R.layout.p1);
rggr = (RadioGroup) findViewById(R.id.rgGr);
rggr.setOnCheckedChangeListener(this);
}
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch (checkedId){
case R.id.rb1:
if(position == 1){
text.setText("this is text 1");
position = 2;
}
}
}
}
If I change the line "text.setText("this is text 1");" to something else. for example setcontentview then it all works. But when I want to change the text, it crashes the moment I select the radio button.