Hello,
I am quite new to Android coding, but I have a question. Right now I am having the code below. The thing is that right now the word changes to the left, center or right from the moment I click a RadioButton. I actually wants it to change only if I click the Generate button. Any tips how I can achieve this? Thanks!
I am quite new to Android coding, but I have a question. Right now I am having the code below. The thing is that right now the word changes to the left, center or right from the moment I click a RadioButton. I actually wants it to change only if I click the Generate button. Any tips how I can achieve this? Thanks!
Code:
public class tutorialOne extends Activity implements OnCheckedChangeListener{
TextView textOut;
EditText textIn;
RadioGroup gravityG, styleG;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tutorial1);
textOut = (TextView) findViewById(R.id.tvChange);
textIn = (EditText) findViewById(R.id.editText1);
gravityG = (RadioGroup) findViewById(R.id.rgGravity);
gravityG.setOnCheckedChangeListener(this);
styleG = (RadioGroup) findViewById(R.id.rgStyle);
styleG.setOnCheckedChangeListener(this);
Button gen = (Button) findViewById(R.id.bGenerate);
gen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
textOut.setText(textIn.getText());
}
});
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch(checkedId){
case R.id.rbLeft:
textOut.setGravity(Gravity.LEFT);
break;
case R.id.rbRight:
textOut.setGravity(Gravity.RIGHT);
break;
case R.id.rbCenter:
textOut.setGravity(Gravity.CENTER);
break;
}
}
}