androidradio-buttondynamic-ui

Why dynamic radiobutton color is white?


I read from a file a lot of data, and i a would like to create the ui from this. I create a lot of textview and a radiobutton, but when i try this on device or emulator i got white text everywhere, why?

If i create a radio button in the xml it is black! but my dynamic radio button color is white :(

public void buildScreen(){

    TextView header = new TextView(context);
    header.setText(dataManager.getHeaderString()+"\n"+dataManager.getqType());
    dataManager.setMainTable(tbl);

    TableRow row;
    for (Map.Entry<String, SimpleQuestionModel> entry : dataManager.getqDict().entrySet()){
        String question = entry.getKey();
        SimpleQuestionModel model = entry.getValue();

        row = new TableRow(context);
        TextView tv = new TextView(context);
        tv.setText(model.getQuestion());
        dataManager.getMainTable().addView(tv);

        RadioGroup rg = new RadioGroup(context);
        rg.setOrientation(RadioGroup.VERTICAL);
        for (int j=0;j<model.getAnswers().size();j++){
            RadioButton rb = new RadioButton(context);
            rb.setText(model.getAnswers().get(j));

            rg.addView(rb);
        }
        dataManager.getqAndA().put(tv, rg);
        row.addView(rg);
        dataManager.getMainTable().addView(row);

    }

}

Here is my class constuctor:

public UIBuilder(Context context, TableLayout tbl) {
    this.context = context;
    this.tbl = tbl;
    dataManager = DataManager.getInstance();
    DataReader dataReader = new DataReader();
    dataReader.readDataFromFile("first.txt");
}

And i call this class like this:

 builder = new UIBuilder(getApplicationContext(), tbl);

    builder.buildScreen();

and tbl is a tablelayout in my xml


Solution

  • Always use the Activity as the Context when instantiating widgets, if you want your theme to be honored. Using any other Context will just use the stock system theme.

    This blog post by Dave Smith explains when to use what Context, including mentioning this problem.