Java Code Examples for android.widget.RadioButton#setText()

The following examples show how to use android.widget.RadioButton#setText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecyclerViewScrollActivity.java    From AndroidDemo with MIT License 6 votes vote down vote up
private void initTab() {
    int padding = Tools.dip2px(this, 10);
    for (int i = 0; i < 20; i++) {
        RadioButton rb = new RadioButton(this);
        rb.setPadding(padding, 0, padding, 0);
        rb.setButtonDrawable(null);
        rb.setGravity(Gravity.CENTER);
        rb.setTag(i * 5);
        rb.setText("Group " + i);
        rb.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
        try {
            rb.setTextColor(getResources().getColorStateList(R.color.bg_tab_text));
        } catch (Exception e) {
            e.printStackTrace();
        }
        rb.setCompoundDrawablesWithIntrinsicBounds(null, null, null, getResources().getDrawable(R.drawable.bg_block_tab));
        rb.setOnCheckedChangeListener(onCheckedChangeListener);
        rg_tab.addView(rb);
    }
    ((RadioButton) rg_tab.getChildAt(0)).setChecked(true);
}
 
Example 2
Source File: ForumSearchActivity.java    From BotLibre with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	RadioButton radio = (RadioButton)findViewById(R.id.personalRadio);
	radio.setText("My Forums");
   	
	Spinner sortSpin = (Spinner) findViewById(R.id.sortSpin);
	ArrayAdapter adapter = new ArrayAdapter(this,
               android.R.layout.simple_spinner_dropdown_item, new String[]{
       			"connects",
       			"connects today",
       			"connects this week",
       			"connects this month",
       			"last connect",
       			"name",
       			"date",
       			"posts",
           		"thumbs up",
           		"thumbs down",
           		"stars"
       });
	sortSpin.setAdapter(adapter);
}
 
Example 3
Source File: RadioGroup1.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.radio_group_1);
    mRadioGroup = (RadioGroup) findViewById(R.id.menu);

    // test adding a radio button programmatically
    RadioButton newRadioButton = new RadioButton(this);
    newRadioButton.setText(R.string.radio_group_snack);
    newRadioButton.setId(R.id.snack);
    LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
            RadioGroup.LayoutParams.WRAP_CONTENT,
            RadioGroup.LayoutParams.WRAP_CONTENT);
    mRadioGroup.addView(newRadioButton, 0, layoutParams);

    // test listening to checked change events
    String selection = getString(R.string.radio_group_selection);
    mRadioGroup.setOnCheckedChangeListener(this);
    mChoice = (TextView) findViewById(R.id.choice);
    mChoice.setText(selection + mRadioGroup.getCheckedRadioButtonId());

    // test clearing the selection
    Button clearButton = (Button) findViewById(R.id.clear);
    clearButton.setOnClickListener(this);
}
 
Example 4
Source File: ForumSearchActivity.java    From BotLibre with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	RadioButton radio = (RadioButton)findViewById(R.id.personalRadio);
	radio.setText("My Forums");
   	
	Spinner sortSpin = (Spinner) findViewById(R.id.sortSpin);
	ArrayAdapter adapter = new ArrayAdapter(this,
               android.R.layout.simple_spinner_dropdown_item, new String[]{
       			"connects",
       			"connects today",
       			"connects this week",
       			"connects this month",
       			"last connect",
       			"name",
       			"date",
       			"posts",
           		"thumbs up",
           		"thumbs down",
           		"stars"
       });
	sortSpin.setAdapter(adapter);
}
 
Example 5
Source File: Dialog.java    From PocketMaps with MIT License 5 votes vote down vote up
public static void showUnitTypeSelector(Activity activity)
{
  AlertDialog.Builder builder1 = new AlertDialog.Builder(activity);
  builder1.setTitle(R.string.units);
  builder1.setCancelable(true);
  
  final RadioButton rb1 = new RadioButton(activity.getBaseContext());
  rb1.setText(R.string.units_metric);

  final RadioButton rb2 = new RadioButton(activity.getBaseContext());
  rb2.setText(R.string.units_imperal);
  
  final RadioGroup rg = new RadioGroup(activity.getBaseContext());
  rg.addView(rb1);
  rg.addView(rb2);
  rg.check(Variable.getVariable().isImperalUnit() ? rb2.getId() : rb1.getId());
  
  builder1.setView(rg);
  OnClickListener listener = new OnClickListener()
  {
    @Override
    public void onClick(DialogInterface dialog, int buttonNr)
    {
      Variable.getVariable().setImperalUnit(rb2.isChecked());
      Variable.getVariable().saveVariables(Variable.VarType.Base);
    }
  };
  builder1.setPositiveButton(R.string.ok, listener);
  AlertDialog alert11 = builder1.create();
  alert11.show();
}
 
Example 6
Source File: FileChooser.java    From MifareClassicTool with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Update the file list and the components that depend on it
 * (e.g. disable the open file button if there is no file).
 * @param path Path to the directory which will be listed.
 * @return True if directory is empty. False otherwise.
 */
private boolean updateFileIndex(File path) {
    File[] files = path.listFiles();

    // Refresh file list.
    if (files != null && files.length > 0) {
        Arrays.sort(files);
        mGroupOfFiles.removeAllViews();

        for(File f : files) {
            RadioButton r = new RadioButton(this);
            r.setText(f.getName());
            mGroupOfFiles.addView(r);
        }
        // Check first file.
        ((RadioButton)mGroupOfFiles.getChildAt(0)).setChecked(true);
        mChooserButton.setEnabled(true);
        if (mDeleteFile != null) {
            mDeleteFile.setEnabled(mDeleteFileEnabled);
        }
        return false;
    } else {
        // No files in directory.
        mChooserButton.setEnabled(false);
        if (mDeleteFile != null) {
            mDeleteFile.setEnabled(false);
        }
        Intent intent = getIntent();
        String chooserText = "";
        if (intent.hasExtra(EXTRA_CHOOSER_TEXT)) {
            chooserText = intent.getStringExtra(EXTRA_CHOOSER_TEXT);
        }
        mChooserText.setText(chooserText
                + "\n   --- "
                + getString(R.string.text_no_files_in_chooser)
                + " ---");
    }
    return true;
}
 
Example 7
Source File: ScriptSearchActivity.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	RadioButton radio = (RadioButton)findViewById(R.id.personalRadio);
	radio.setText("My Scripts");
}
 
Example 8
Source File: WizardStepZero.java    From CameraV with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater li, ViewGroup container, Bundle savedInstanceState) {
	super.onCreateView(li, container, savedInstanceState);
	rootView = li.inflate(R.layout.fragment_wizard_step_zero, null);
	
	languageChoices = (RadioGroup) rootView.findViewById(R.id.wizard_language_choices);
	languageMap = (ILanguageMap) getArguments().getSerializable(Codes.Extras.SET_LOCALES);
	
	for(String l : languageMap.getLabels()) {
		RadioButton rb = new RadioButton(a);
		rb.setText(l);
		rb.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				for(int l=0; l<languageChoices.getChildCount(); l++) {
					if(v.equals(languageChoices.getChildAt(l))) {
						choice = l;
						break;
					}
				}
				
			}
			
		});

		languageChoices.addView(rb);
	}
	
	langKey = getArguments().getString(Codes.Extras.LOCALE_PREF_KEY);
	
	commit = (Button) rootView.findViewById(R.id.wizard_commit);
	commit.setOnClickListener(this);
	
	return rootView;
}
 
Example 9
Source File: TypeContentIndexPageAdapter.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
/**
 * 过滤条件的item
 */
public View getForumFilterItem(int position, View convertView) {
    if (convertView == null) {
        convertView = View.inflate(context, R.layout.item_forum_filter_recomm, null);
    }
    RadioGroup group = ViewHolder.get(convertView, R.id.radio);

    int index = getHomePageIndex(position);
    final Recommend recommend = homePage.get(index).getRecommend();
    ArrayList<ThreadConfig> threadConfigItems = recommend.getThreadConfigs();

    int[] ids = {R.id.radioButton1, R.id.radioButton2, R.id.radioButton3, R.id.radioButton4};
    group.check(ids[recommend.getForumFilterSelectIndex()]);

    for (int i = 0; i < ids.length; i++) {
        RadioButton radioButton = ViewHolder.get(convertView, ids[i]);
        if (threadConfigItems != null && i < threadConfigItems.size()) {
            ThreadConfig item = threadConfigItems.get(i);
            radioButton.setVisibility(View.VISIBLE);
            radioButton.setText(getFilterItemTitle(item));
        } else {
            radioButton.setVisibility(View.GONE);
        }
        final int ii = i;
        radioButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                filterItemClick(recommend, ii);
            }
        });
    }
    return convertView;
}
 
Example 10
Source File: MultiLineRadioGroupTest.java    From MultiLineRadioGroup with MIT License 5 votes vote down vote up
@Test
public void multiLineRadioGroupOnCheckedChangedEmitOnChecked() throws InterruptedException {
    Context appContext = InstrumentationRegistry.getTargetContext();
    MultiLineRadioGroup radioGroup = new MultiLineRadioGroup(appContext);
    MultilineOnCheckedChangeListener listener = new MultilineOnCheckedChangeListener();
    radioGroup.setOnCheckedChangeListener(listener);

    final RadioButton firstButton = new RadioButton(appContext);
    firstButton.setText("first");
    firstButton.setId(R.id.multi_line_radio_group_default_radio_button);
    radioGroup.addView(firstButton);

    radioGroup.check(R.id.multi_line_radio_group_default_radio_button);
    assertEquals(1, listener.count);
    assertEquals(Collections.singletonList("first"), listener.buttonText);

    radioGroup.clearCheck();
    assertEquals(2, listener.count);
    assertEquals(Arrays.asList("first", "first"), listener.buttonText);

    radioGroup.check("first");
    assertEquals(3, listener.count);
    assertEquals(Arrays.asList("first", "first", "first"),
            listener.buttonText);

    radioGroup.clearCheck();
    assertEquals(4, listener.count);
    assertEquals(Arrays.asList("first", "first", "first", "first"),
            listener.buttonText);

    radioGroup.checkAt(0);
    assertEquals(5, listener.count);
    assertEquals(Arrays.asList("first", "first", "first", "first", "first"),
            listener.buttonText);
}
 
Example 11
Source File: MultiLineRadioGroupTest.java    From MultiLineRadioGroup with MIT License 5 votes vote down vote up
@Test
public void multiLIneRadioGroupOnCheckChangeEmitsOnClearCheck() throws InterruptedException {
    Context appContext = InstrumentationRegistry.getTargetContext();
    final MultiLineRadioGroup radioGroup = new MultiLineRadioGroup(appContext);
    MultilineOnCheckedChangeListener listener = new MultilineOnCheckedChangeListener();
    radioGroup.setOnCheckedChangeListener(listener);

    final RadioButton firstButton = new RadioButton(appContext);
    firstButton.setText("first");
    firstButton.setId(R.id.multi_line_radio_group_default_radio_button);
    radioGroup.addView(firstButton);
    assertEquals(0, listener.count);

    clickButton(firstButton);
    assertEquals(1, listener.count);

    InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            radioGroup.clearCheck();
        }
    });

    assertEquals(Arrays.asList("first", "first"), listener.buttonText);
    assertEquals(Arrays.asList(true, false), listener.buttonState);
    assertEquals(2, listener.count);
}
 
Example 12
Source File: ChannelSearchActivity.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	RadioButton radio = (RadioButton)findViewById(R.id.personalRadio);
	radio.setText("My Channels");
   	
	Spinner sortSpin = (Spinner) findViewById(R.id.sortSpin);
	@SuppressWarnings("unchecked")
	ArrayAdapter adapter = new ArrayAdapter(this,
               android.R.layout.simple_spinner_dropdown_item, new String[]{
       			"connects",
       			"connects today",
       			"connects this week",
       			"connects this month",
       			"last connect",
       			"name",
       			"date",
           		"messages",
           		"users online",
           		"thumbs up",
           		"thumbs down",
           		"stars"
       });
	sortSpin.setAdapter(adapter);
}
 
Example 13
Source File: ChannelSearchActivity.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	RadioButton radio = (RadioButton)findViewById(R.id.personalRadio);
	radio.setText("My Channels");
   	
	Spinner sortSpin = (Spinner) findViewById(R.id.sortSpin);
	@SuppressWarnings("unchecked")
	ArrayAdapter adapter = new ArrayAdapter(this,
               android.R.layout.simple_spinner_dropdown_item, new String[]{
       			"connects",
       			"connects today",
       			"connects this week",
       			"connects this month",
       			"last connect",
       			"name",
       			"date",
           		"messages",
           		"users online",
           		"thumbs up",
           		"thumbs down",
           		"stars"
       });
	sortSpin.setAdapter(adapter);
}
 
Example 14
Source File: ChannelSearchActivity.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	RadioButton radio = (RadioButton)findViewById(R.id.personalRadio);
	radio.setText("My Channels");
   	
	Spinner sortSpin = (Spinner) findViewById(R.id.sortSpin);
	@SuppressWarnings("unchecked")
	ArrayAdapter adapter = new ArrayAdapter(this,
               android.R.layout.simple_spinner_dropdown_item, new String[]{
       			"connects",
       			"connects today",
       			"connects this week",
       			"connects this month",
       			"last connect",
       			"name",
       			"date",
           		"messages",
           		"users online",
           		"thumbs up",
           		"thumbs down",
           		"stars"
       });
	sortSpin.setAdapter(adapter);
}
 
Example 15
Source File: AvatarSearchActivity.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	RadioButton radio = (RadioButton)findViewById(R.id.personalRadio);
	radio.setText("My Avatars");
}
 
Example 16
Source File: WidgetFragment.java    From mobile-android-survey-app with MIT License 5 votes vote down vote up
protected RadioButton getRadioButton(Integer id, String text, String tag, String value) {
    RadioButton radioButton = new RadioButton(getActivity());
    radioButton.setId(id);
    radioButton.setText(text);
    radioButton.setTag(tag);
    radioButton.setTextAppearance(getActivity(), R.style.RadioButton_Full);
    radioButton.setLayoutParams(getLayoutParams(labelDescription.getPaddingLeft(), labelDescription.getPaddingLeft() / 2, labelDescription.getPaddingRight(), labelDescription.getPaddingLeft() / 2));
    if (value != null && value.equals(tag)) {
        radioButton.setChecked(true);
    }
    else {
        radioButton.setChecked(false);
    }
    return radioButton;
}
 
Example 17
Source File: RadioElement.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected View createView(Context c) {
    Log.i(TAG, "[" + id + "]createView()");
    ScrollView radioView = new ScrollView(c);
    mRadioGroup = new RadioGroup(c);
    mRadioGroup.setOrientation(LinearLayout.VERTICAL);
    rblist = new ArrayList<RadioButton>(values.length);

    if (answer == null)
        answer = "";
    for (String value : values) {
        Log.d(TAG, "..." + value + ":" + getLabelFromValue(value));
        RadioButton rb = new RadioButton(c);
        rb.setText(getLabelFromValue(value));
        rb.setTag(value);
        if (value.equals(answer)) {
            rb.setChecked(true);
        }
        rblist.add(rb);
        mRadioGroup.addView(rb);
    }
    mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            setAnswer(String.valueOf(group.findViewById(checkedId).getTag
                    ()));
        }
    });
    radioView.addView(mRadioGroup, new ViewGroup.LayoutParams(-1, -1));
    return encapsulateQuestion(c, radioView);
}
 
Example 18
Source File: AdapterDialog.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public View getView(final int position, View convertView, ViewGroup parent) {

    LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

    convertView = null;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.rg_adapter_dialog, null);
        name_tv = (RadioButton) convertView.findViewById(R.id.rg_radioButton);
        StructCountry structCountry = countrylist.get(position);
        name_tv.setText(structCountry.getName());
    }

    name_tv.setChecked(countrylist.get(position).getId() == mSelectedVariation);
    name_tv.setTag(position);
    name_tv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            mSelectedVariation = (Integer) v.getTag();

            FragmentRegister.positionRadioButton = countrylist.get(position).getId();
            mSelectedVariation = countrylist.get(position).getId();
            notifyDataSetChanged();

            FragmentRegister.edtCodeNumber.setText(("+ " + countrylist.get(position).getCountryCode()));
            if (countrylist.get(position).getPhonePattern() != null || countrylist.get(position).getPhonePattern().equals(" ")) {
                FragmentRegister.edtPhoneNumber.setMask((countrylist.get(position).getPhonePattern().replace("X", "#").replace(" ", "-")));
            } else {
                FragmentRegister.edtPhoneNumber.setMaxLines(18);
                FragmentRegister.edtPhoneNumber.setMask("##################");
            }
            FragmentRegister.btnChoseCountry.setText((countrylist.get(position).getName()));
            FragmentRegisterViewModel.isoCode = countrylist.get(position).getAbbreviation();
            FragmentRegisterViewModel.btnOk.performClick();
            FragmentRegisterViewModel.dialogChooseCountry.dismiss();
        }
    });

    return convertView;
}
 
Example 19
Source File: MidiInputCreateDialog.java    From PdDroidPublisher with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) 
{
	super.onCreate(savedInstanceState);
	
	setTitle("IP MIDI Input creation");
	
	LinearLayout view = new LinearLayout(getContext());
	view.setOrientation(LinearLayout.VERTICAL);
	
	RadioGroup rg = new RadioGroup(getContext());
	
	final RadioButton rbMulticast = new RadioButton(getContext());
	rbMulticast.setText("RAW/Multicast");
	
	final RadioButton rbUnicast = new RadioButton(getContext());
	rbUnicast.setText("RAW/Unicast");
	
	rg.addView(rbUnicast);
	rg.addView(rbMulticast);
	
	rbUnicast.setChecked(true);
	
	final EditText tvIP = new EditText(getContext());
	tvIP.setText("127.0.0.1");
	tvIP.setEnabled(rbMulticast.isChecked());
	
	final EditText tvPORT = new EditText(getContext());
	tvPORT.setInputType(InputType.TYPE_CLASS_NUMBER);
	tvPORT.setText("21929");
	
	Button btOk = new Button(getContext());
	btOk.setText("Create");
	
	rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
		
		@Override
		public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
			tvIP.setEnabled(rbMulticast.isChecked());
		}
	});
	
	btOk.setOnClickListener(new View.OnClickListener() {
		
		@Override
		public void onClick(View v) 
		{
			IPMidiInput input = new IPMidiInput();
			input.multicast = rbMulticast.isChecked();
			input.ip = rbMulticast.isChecked() ? tvIP.getText().toString() : null;
			input.port = Integer.parseInt(tvPORT.getText().toString());
			device.inputs.add(input);
			MidiInputCreateDialog.this.dismiss();
		}
	});
	
	view.addView(rg);
	view.addView(tvIP);
	view.addView(tvPORT);
	view.addView(btOk);
	
	setContentView(view);
}
 
Example 20
Source File: ExportDialogFragment.java    From mytracks with Apache License 2.0 2 votes vote down vote up
/**
 * Sets an external storage option.
 * 
 * @param radioButton the radio button
 * @param trackFileFormat the track file format
 */
private void setExternalStorageOption(RadioButton radioButton, TrackFileFormat trackFileFormat) {
  radioButton.setText(getString(R.string.export_external_storage_option, trackFileFormat.name(),
      FileUtils.getPathDisplayName(trackFileFormat.getExtension())));
}