i m trying to get the Value from RadioButton that is Created by String of Array
i m using OClickListener() to get the Value from RadioButton but Error is showing
" java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.RadioButton
"
Here is my Code,Please check
for(int i =0; i<ab.length;i++)
{
RadioButton radioButtonView = new RadioButton(this);
radioButtonView.setText(ab[i]);
radioGroup.addView(radioButtonView, p);
}
Button btnDisplay = (Button) findViewById(R.id.button1);
btnDisplay.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
// get selected radio button from radioGroup
int selectedId = radioGroup.getCheckedRadioButtonId();
// find the radiobutton by returned id
String s = ((RadioButton) v ).getText().toString();
Toast.makeText(Radio_Button.this, "This is: " + s,Toast.LENGTH_LONG).show();
}
and LogCat is
FATAL EXCEPTION: main
Process: com.example.radiobuttondynamic, PID: 4741
java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.RadioButton
at com.example.radiobuttondynamic.Radio_Button$1.onClick(Radio_Button.java:64)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Please Give Suggestion to Correct it
thanks thanks