I am dynamically creating radio buttons as per the count given in the edit text. I want to edit the name of the radiobutton after it gets created dynamically in the app, like the user has the privilege to name the radio button in the app. How should I do that android studio This is my code for creating dyanmic radiobuttons so far. Here in the code rbn.setText("Radiobutton"+i) names the radiobutton as Radiobutton1, Radiobutton2, etc. instead of that I want to change the name of that in the app dynamically and write the name of the radiobutton one by one, help would appreciated please!
package com.example.EZPoll;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
public class Public_create extends AppCompatActivity {
EditText mEtNumOfRadioBtns;
Button mBtnAdd;
RadioGroup mRgAllButtons;
String option_name;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_public_create);
mEtNumOfRadioBtns = findViewById(R.id.et_no);
mBtnAdd = (Button) findViewById(R.id.btn);
mRgAllButtons = (RadioGroup)findViewById(R.id.radiogroup);
mBtnAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int number=Integer.parseInt(mEtNumOfRadioBtns.getText().toString().trim());
for (int i = 1; i <= number ; i++) {
RadioButton rbn = new RadioButton(Public_create.this);
rbn.setId(View.generateViewId());
rbn.setText("Radiobutton "+i);
mRgAllButtons.addView(rbn);
}
}
});
}
}```