0

フラグメントがあり、プログラムで動的なラジオ ボタンをラジオ グループに追加しようとしました。ラジオボタンは追加されていますが、テキストは設定されていません。

これは私のコードです:

private View myFragmentView;
private Context context;
private RadioGroup radioGrup;

private ArrayList<Language> allLanguages;

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    allLanguages=MyAsyncTask.getAllLanguages();
    myFragmentView =  inflater
            .inflate(R.layout.language_view, container, false);
    context = this.getActivity().getApplicationContext();

    radioGrup = (RadioGroup)myFragmentView.findViewById(R.id.allLanguages);
    addRadioButton();

    return myFragmentView;
}

@SuppressLint({ "ResourceAsColor", "NewApi" })
private void addRadioButton(){
    for(Language language:allLanguages){
        RadioButton newRadioButton = new RadioButton(context);
        newRadioButton = new RadioButton(context);
        newRadioButton.setText("something");
        newRadioButton.setTextColor(android.R.color.black);
        newRadioButton.setLayoutParams 
          (new LayoutParams 
                  (LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        radioGrup.addView(newRadioButton);
    }
}

誰かが私を助けることができますか?

4

1 に答える 1