List of usage examples for android.widget RadioGroup addView
public void addView(View child)
Adds a child view.
From source file:edu.csh.coursebrowser.SettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); this.setTitle("Settings"); final SharedPreferences sp = SchoolActivity.sp; LinearLayout ll = (LinearLayout) this.findViewById(R.id.settings_layout); ll.setGravity(Gravity.CENTER);//from w ww . java 2 s .c o m final TextView tv = new TextView(this); if (!sp.contains("quarter")) { SharedPreferences.Editor e = sp.edit(); e.putString("quarter", "20122"); e.commit(); } tv.setText("Current Quarter: " + sp.getString("quarter", "20122")); Button b = new Button(this); b.setText("Change Quarter"); ll.addView(tv); ll.addView(b); ll.setPadding(10, 10, 10, 10); b.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { AlertDialog.Builder changeQuarter = new AlertDialog.Builder(SettingsActivity.this); changeQuarter.setTitle("Change Quarter"); changeQuarter.setMessage("Select New Quarter"); final RadioButton ld = new RadioButton(SettingsActivity.this); ld.setText("20121"); ld.setId(1); final RadioButton s = new RadioButton(SettingsActivity.this); s.setText("20122 (Current)"); s.setId(2); final RadioButton d = new RadioButton(SettingsActivity.this); d.setText("20123"); d.setId(3); final RadioGroup rg = new RadioGroup(SettingsActivity.this); rg.addView(ld); rg.addView(s); rg.addView(d); changeQuarter.setView(rg); changeQuarter.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }); changeQuarter.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String q; int n = rg.getCheckedRadioButtonId(); if (n == 1) q = "20121"; else if (n == 2) q = "20122"; else q = "20123"; SharedPreferences.Editor edit = sp.edit(); edit.putString("quarter", q); edit.commit(); SettingsActivity.this.finish(); } }); changeQuarter.show(); } }); }
From source file:com.github.johnpersano.supertoasts.demo.fragments.AttributeRadioGroupFragment.java
@Nullable @Override/* www .j ava2 s .com*/ @SuppressWarnings("ConstantConditions") public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.fragment_attribute_radiogroup, container, false); // Make sure the Fragment has found its arguments if (this.getArguments() == null) { throw new IllegalArgumentException( getClass().getName().concat(" cannot be " + "instantiated without arguments.")); } final TextView subtitleTextView = (TextView) view.findViewById(R.id.subtitle); subtitleTextView.setText(getArguments().getString(ARG_SUBTITLE)); final TextView summaryTextView = (TextView) view.findViewById(R.id.summary); summaryTextView.setText(getArguments().getString(ARG_SUMMARY)); final RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.radiogroup); for (String string : getArguments().getStringArrayList(ARG_ARRAY)) { final RadioButton radioButton = new RadioButton(getActivity()); radioButton.setText(string); radioButton.setId(ViewUtils.generateViewId()); radioGroup.addView(radioButton); } radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PreferenceManager.getDefaultSharedPreferences(getActivity()).edit() .putInt(getArguments().getString(ARG_TITLE), group.indexOfChild(group.findViewById(group.getCheckedRadioButtonId()))) .commit(); } }); // RadioGroup.check() is misleading, we must check the RadioButton manually ((RadioButton) radioGroup.getChildAt(PreferenceManager.getDefaultSharedPreferences(getActivity()) .getInt(getArguments().getString(ARG_TITLE), 0))).setChecked(true); return view; }
From source file:com.sweetiepiggy.littlepro.QuestionFragment.java
private void createMultipleChoice(View v, List<String> answerChoices) { v.findViewById(R.id.answer).setVisibility(View.GONE); RadioGroup radioGroup = (RadioGroup) v.findViewById(R.id.answerRadioGroup); for (String answerChoice : answerChoices) { RadioButton radioButton = new RadioButton(getActivity()); radioButton.setText(answerChoice); radioButton.setTextAppearance(getActivity(), R.style.Entry); radioGroup.addView(radioButton); if (answerChoice == mAnswer) { radioButton.toggle();//from w w w . j a va2 s .c o m } if (mSubmitted) { radioButton.setEnabled(false); } } }
From source file:org.openmrs.mobile.activities.formdisplay.FormDisplayPageFragment.java
@Override public void createAndAttachSelectQuestionRadioButton(Question question, LinearLayout sectionLinearLayout) { TextView textView = new TextView(getActivity()); textView.setPadding(20, 0, 0, 0);//w w w . ja va 2s .c o m textView.setText(question.getLabel()); RadioGroup radioGroup = new RadioGroup(getActivity()); for (Answer answer : question.getQuestionOptions().getAnswers()) { RadioButton radioButton = new RadioButton(getActivity()); radioButton.setText(answer.getLabel()); radioGroup.addView(radioButton); } SelectOneField radioGroupField = new SelectOneField(question.getQuestionOptions().getAnswers(), question.getQuestionOptions().getConcept()); LinearLayout.LayoutParams linearLayoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); sectionLinearLayout.addView(textView); sectionLinearLayout.addView(radioGroup); sectionLinearLayout.setLayoutParams(linearLayoutParams); SelectOneField selectOneField = getSelectOneField(radioGroupField.getConcept()); if (selectOneField != null) { if (selectOneField.getChosenAnswerPosition() != -1) { RadioButton radioButton = (RadioButton) radioGroup .getChildAt(selectOneField.getChosenAnswerPosition()); radioButton.setChecked(true); } setOnCheckedChangeListener(radioGroup, selectOneField); } else { setOnCheckedChangeListener(radioGroup, radioGroupField); selectOneFields.add(radioGroupField); } }
From source file:com.android.fastexample.ui.activity.MainActivity.java
@Override protected void initData() { fragments.add(new FragmentPage1()); fragments.add(new FragmentPage2()); fragments.add(new FragmentPage3()); fragments.add(new FragmentPage4()); fragments.add(new FragmentPage5()); RadioGroup rgs = (RadioGroup) findViewById(R.id.tabs_rg); String[] moduldes = { "", "", "", "", "" }; int[] imgs = { R.drawable.tab_home_btn, R.drawable.tab_message_btn, R.drawable.tab_more_btn, R.drawable.tab_selfinfo_btn, R.drawable.tab_square_btn }; int width = windowWidth / moduldes.length; for (int i = 0; i < moduldes.length; i++) { String moduleName = moduldes[i]; RadioButton radioButton = (RadioButton) LayoutInflater.from(this).inflate(R.layout.home_radiobutton, null);//from ww w . ja v a 2 s.c om radioButton.setLayoutParams(new ViewGroup.LayoutParams(width, ViewGroup.LayoutParams.MATCH_PARENT)); radioButton.setText(moduleName); Drawable drawable = getResources().getDrawable(imgs[i]); radioButton.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null); rgs.addView(radioButton); } FragmentTabAdapter tabAdapter = new FragmentTabAdapter(this, fragments, R.id.tab_content, rgs); tabAdapter.setOnRgsExtraCheckedChangedListener(new FragmentTabAdapter.OnRgsExtraCheckedChangedListener() { @Override public void OnRgsExtraCheckedChanged(RadioGroup radioGroup, int checkedId, int index) { System.out.println("Extra---- " + index + " checked!!! "); } }); }
From source file:com.cairoconfessions.MainActivity.java
public void report(View view) { final EditText edit = new EditText(this); final RadioGroup choices = new RadioGroup(this); edit.setText("I would like to report this confession"); final String[] selectedItem = getResources().getStringArray(R.array.report_choices); for (int i = 0; i < selectedItem.length; i++) { RadioButton choice = new RadioButton(this); choice.setText(selectedItem[i]); choices.addView(choice); }//from w w w. j a va 2s .com choices.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { // checkedId is the RadioButton selected edit.setText("I would like to report this confession as " + ((RadioButton) group.findViewById(checkedId)).getText().toString()); } }); LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); ll.addView(choices); ll.addView(edit); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Choose which categories:").setView(ll) .setPositiveButton(R.string.send, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User clicked OK button reportReceived(); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User clicked Cancel button } }).show(); }
From source file:com.ubikod.capptain.android.sdk.reach.activity.CapptainPollActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { /* Init layout */ super.onCreate(savedInstanceState); /* If no content, nothing to do, super class already called finish */ if (mContent == null) return;/*from w ww . ja v a 2 s .c o m*/ /* Render questions */ LinearLayout questionsLayout = getView("questions"); JSONArray questions = mContent.getQuestions(); LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); try { for (int i = 0; i < questions.length(); i++) { /* Get question */ JSONObject question = questions.getJSONObject(i); /* Inflate question layout */ LinearLayout questionLayout = (LinearLayout) layoutInflater .inflate(getLayoutId("capptain_poll_question"), null); /* Set question's title */ TextView questionTitle = (TextView) questionLayout.findViewById(getId("question_title")); questionTitle.setText(question.getString("title")); /* Set choices */ RadioGroup choicesView = (RadioGroup) questionLayout.findViewById(getId("choices")); choicesView.setTag(question); JSONArray choices = question.getJSONArray("choices"); int choiceViewId = 0; for (int j = 0; j < choices.length(); j++) { /* Get choice */ JSONObject choice = choices.getJSONObject(j); /* Inflate choice layout */ RadioButton choiceView = (RadioButton) layoutInflater .inflate(getLayoutId("capptain_poll_choice"), null); /* Each choice is a radio button */ choiceView.setId(choiceViewId++); choiceView.setTag(choice.getString("id")); choiceView.setText(choice.getString("title")); choiceView.setChecked(choice.getBoolean("default")); choicesView.addView(choiceView); } /* Add to parent layouts */ questionsLayout.addView(questionLayout); /* Watch state */ mRadioGroups.add(choicesView); choicesView.setOnCheckedChangeListener(mRadioGroupListener); } } catch (JSONException jsone) { /* Won't happen */ } /* Disable action if a choice is not selected */ updateActionState(); }
From source file:com.partypoker.poker.engagement.reach.activity.EngagementPollActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { /* Init layout */ super.onCreate(savedInstanceState); /* If no content, nothing to do, super class already called finish */ if (mContent == null) return;// w w w . ja va 2 s. c om /* Render questions */ LinearLayout questionsLayout = getView("questions"); JSONArray questions = mContent.getQuestions(); LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); try { for (int i = 0; i < questions.length(); i++) { /* Get question */ JSONObject question = questions.getJSONObject(i); /* Inflate question layout */ LinearLayout questionLayout = (LinearLayout) layoutInflater .inflate(getLayoutId("engagement_poll_question"), null); /* Set question's title */ TextView questionTitle = (TextView) questionLayout.findViewById(getId("question_title")); questionTitle.setText(question.getString("title")); /* Set choices */ RadioGroup choicesView = (RadioGroup) questionLayout.findViewById(getId("choices")); choicesView.setTag(question); JSONArray choices = question.getJSONArray("choices"); int choiceViewId = 0; for (int j = 0; j < choices.length(); j++) { /* Get choice */ JSONObject choice = choices.getJSONObject(j); /* Inflate choice layout */ RadioButton choiceView = (RadioButton) layoutInflater .inflate(getLayoutId("engagement_poll_choice"), null); /* Each choice is a radio button */ choiceView.setId(choiceViewId++); choiceView.setTag(choice.getString("id")); choiceView.setText(choice.getString("title")); choiceView.setChecked(choice.optBoolean("isDefault")); choicesView.addView(choiceView); } /* Add to parent layouts */ questionsLayout.addView(questionLayout); /* Watch state */ mRadioGroups.add(choicesView); choicesView.setOnCheckedChangeListener(mRadioGroupListener); } } catch (JSONException jsone) { /* Drop on parsing error */ mContent.dropContent(this); finish(); return; } /* Disable action if a choice is not selected */ updateActionState(); }
From source file:com.google.code.twisty.Twisty.java
private void updateGameRadioButtons(RadioGroup rg) { rg.removeAllViews();/*w ww . j a v a2 s .c o m*/ game_paths.clear(); int id = 0; for (String path : discovered_games) { RadioButton rb = new RadioButton(Twisty.this); rb.setText(new File(path).getName()); rg.addView(rb); id = rb.getId(); game_paths.put(id, path); } }
From source file:com.google.code.twisty.Twisty.java
private void updateRestoreRadioButtons(RadioGroup rg) { rg.removeAllViews();/* w ww . ja va 2 s. c o m*/ int id = 0; String[] gamelist = new File(savegame_dir).list(); for (String filename : gamelist) { RadioButton rb = new RadioButton(Twisty.this); rb.setText(filename); rg.addView(rb); id = rb.getId(); } rg.check(id); // by default, check the last item }