Hi everybody I have been working on the same issue for hours.What I wanted to achieve is to set my fonts to TextView
and Its finally done.However I am having trouble with RadioGroup
The problem is that when I run my app and checked RadioButton It seems working.Then I have noticed that the other RadioButton is not working.I wasnt able to set anything to Textview When I click on that What am i doing wrong here
Here what I have so far
@EDIT
@Override
public void onCheckedChanged(RadioGroup rdg, int arg1) {
///this is where I need help.How can i set returning values
RadioButton Che= (RadioButton) findViewById(R.id.Che);
RadioButton Ser= (RadioButton) findViewById(R.id.ser);
if(arg1 ==R.id.Che ){
cutomfonts=getFirstFont();
myTextView.setTypeface(cutomfonts);
}else if(arg1 == R.id.ser){
cutomfonts=getSecondFont();
myTextView.setTypeface(cutomfonts);
}
}
This is Xml File
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="68dp"
android:layout_marginTop="158dp" >
<RadioButton
android:id="@+id/Che"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="RadioButton" />
<RadioButton
android:id="@+id/ser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
</RadioGroup>
<TextView
android:id="@+id/my_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/radioGroup1"
android:layout_alignParentTop="true"
android:layout_marginLeft="23dp"
android:layout_marginTop="57dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
As per my knowledge your you are not register Che
or ser
radiobutton, Eclipse not find xml defined Che
and ser
RadioButton value in java file. So you first register do following things,
Che= (RadioButton) findViewById(R.id.Che);
ser= (RadioButton) findViewById(R.id.ser);
after using above code you can try to run it's work perfect. also i put my own code using if else this is also work for you,
Now you can implement onCheckedChanged()
override method in following way,
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
if(arg1 == R.id.Che){
cutomfonts=getFirstFont();
myTextView.setTypeface(cutomfonts);
}else if(arg1 == R.id.ser){
cutomfonts=getSecondFont();
myTextView.setTypeface(cutomfonts);
}
}
Hope this help you!