Example usage for android.widget RadioButton setChecked

List of usage examples for android.widget RadioButton setChecked

Introduction

In this page you can find the example usage for android.widget RadioButton setChecked.

Prototype

@Override
public void setChecked(boolean checked) 

Source Link

Document

Changes the checked state of this button.

Usage

From source file:Main.java

public static void switchRadio(Boolean value, RadioButton trueRadio, RadioButton falseRadio) {
    if (value == null)
        return;//www. j  a va  2  s.  com
    if (value)
        trueRadio.setChecked(true);
    else
        falseRadio.setChecked(true);
}

From source file:com.eleybourn.bookcatalogue.dialogs.StandardDialogs.java

/**
 * Select a custom item from a list, and call halder when/if item is selected.
 *//*from  ww  w . j  a v a 2 s.c o  m*/
public static void selectItemDialog(LayoutInflater inflater, String message, ArrayList<SimpleDialogItem> items,
        SimpleDialogItem selectedItem, final SimpleDialogOnClickListener handler) {
    // Get the view and the radio group
    final View root = inflater.inflate(R.layout.select_list_dialog, null);
    TextView msg = (TextView) root.findViewById(R.id.message);

    // Build the base dialog
    final AlertDialog.Builder builder = new AlertDialog.Builder(inflater.getContext()).setView(root);
    if (message != null && !message.equals("")) {
        msg.setText(message);
    } else {
        msg.setVisibility(View.GONE);
    }

    final AlertDialog dialog = builder.create();

    // Create the listener for each item
    OnClickListener listener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            SimpleDialogItem item = (SimpleDialogItem) ViewTagger.getTag(v, R.id.TAG_DIALOG_ITEM);
            // For a consistent UI, make sure the selector is checked as well. NOT mandatory from
            // a functional point of view, just consistent
            if (!(v instanceof RadioButton)) {
                RadioButton btn = item.getSelector(v);
                if (btn != null) {
                    btn.setChecked(true);
                    btn.invalidate();
                }
            }
            //
            // It would be nice to have the other radio buttons reflect the new state before it
            // disappears, but not really worth the effort. Esp. since the code below does not work...
            // and the dialog disappears too fast to make this worthwhile.
            //
            //LinearLayout list = (LinearLayout)root.findViewById(R.id.list);
            //for(int i = 0; i < list.getChildCount(); i++) {
            //   View child = list.getChildAt(i);
            //   SimpleDialogItem other = (SimpleDialogItem)ViewTagger.getTag(child, R.id.TAG_DIALOG_ITEM);
            //   RadioButton btn = other.getSelector(child);
            //   btn.setSelected(other == item);
            //   btn.invalidate();
            //}
            dialog.dismiss();
            handler.onClick(item);
        }
    };

    // Add the items to the dialog
    LinearLayout list = (LinearLayout) root.findViewById(R.id.list);
    for (SimpleDialogItem item : items) {
        View v = item.getView(inflater);
        v.setBackgroundResource(android.R.drawable.list_selector_background);
        ViewTagger.setTag(v, R.id.TAG_DIALOG_ITEM, item);
        list.addView(v);
        v.setOnClickListener(listener);
        RadioButton btn = item.getSelector(v);
        if (btn != null) {
            ViewTagger.setTag(btn, R.id.TAG_DIALOG_ITEM, item);
            btn.setChecked(item == selectedItem);
            btn.setOnClickListener(listener);
        }
    }
    dialog.show();
}

From source file:org.wheelmap.android.fragment.WheelchairStateFragment.java

@Override
public void onClick(View v) {
    DeselectAllRadioButtons();//from   ww w  .ja  v  a 2 s  .  com
    final RadioButton a = (RadioButton) v;
    a.setChecked(true);
}

From source file:sysnetlab.android.sdc.ui.fragments.ExperimentDataStoreFragment.java

private void setItemSelected(View view, boolean isSelected) {
    RadioButton radioButton = (RadioButton) view.findViewById(R.id.radiobutton_experiment_datastore_selecting);
    radioButton.setChecked(isSelected);
}

From source file:com.pepperonas.truthordare.fragments.FragmentTwoPlayer.java

private void setDefaultData(int i, View v) {
    EditText etName = (EditText) v.findViewById(R.id.et_name);
    EditText etJokers = (EditText) v.findViewById(R.id.et_jokers);
    if (i == 1) {
        etName.setText("Julia");
        etJokers.setText("2");
    } else {/*from w w w . j  a  v  a2  s .c  om*/
        etName.setText("Ismail");
        etJokers.setText("2");
        RadioButton radioMale = (RadioButton) v.findViewById(R.id.rb_male);
        radioMale.setChecked(true);
    }
}

From source file:org.tbrt.aemanager.AeManagerAction.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ae_manager_action);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    Intent intent = getIntent();//from   w w w . java2s. com

    message = intent.getParcelableExtra("MESSAGE");

    TextView t1 = (TextView) findViewById(R.id.type_textView);
    t1.setText(message.getLongMessageType());
    TextView t2 = (TextView) findViewById(R.id.source_textView);
    t2.setText(message.getLongMonitorName());
    TextView t3 = (TextView) findViewById(R.id.event_textView);
    t3.setText(message.getLongEventName());
    TextView t4 = (TextView) findViewById(R.id.status_textView);
    t4.setText(message.getLongStatusCode());
    TextView t5 = (TextView) findViewById(R.id.text_textView);
    t5.setText(message.getMessageText());

    String actionList = message.getActionList() + "A";
    String A0 = "A0A";
    String A1 = "A1A";
    if (actionList.indexOf(A0) == -1) {
        RadioButton r = (RadioButton) findViewById(R.id.a0);
        r.setEnabled(false);
        r.setChecked(false);
    }
    if (actionList.indexOf(A1) == -1) {
        RadioButton r = (RadioButton) findViewById(R.id.a1);
        r.setEnabled(false);
        r.setChecked(false);
    }

    Button buttonSend = (Button) findViewById(R.id.saveButton);
    buttonSend.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            sendAction(v);
        }
    });

    Button buttonCancel = (Button) findViewById(R.id.cancelButton);
    buttonCancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            cancelAction(v);
        }
    });
}

From source file:com.duy.pascal.ui.debug.fragments.FragmentFrame.java

public void displayFrame(CallStack callStack) {
    ArrayList<VariableContext> stacks = callStack.getStacks();
    mListFrame.removeAllViews();//from  ww w.  ja  v a  2  s.  c om
    for (int i = 0; i < stacks.size(); i++) {
        MonospaceRadioButton radioButton = new MonospaceRadioButton(getActivity());
        radioButton.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        radioButton.setText(stacks.get(i).toString());
        radioButton.setOnCheckedChangeListener(new OnFrameChangeListener(stacks.get(i)));
        mListFrame.addView(radioButton);
    }
    RadioButton rad = (RadioButton) mListFrame.getChildAt(mListFrame.getChildCount() - 1);
    rad.setChecked(true);
}

From source file:com.jdom.axis.and.allies.view.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.settings);//from   ww  w.  j a  v  a  2s .  c  o m

    RadioButton button1942 = (RadioButton) findViewById(R.id.version_1942);
    RadioButton buttonRevised = (RadioButton) findViewById(R.id.version_revised);

    GameModel gameModel = getGameModel();
    button1942.setChecked(gameModel.getVersion().endsWith("1942"));
    buttonRevised.setChecked(gameModel.getVersion().endsWith("Revised"));
}

From source file:org.gnucash.android.export.ExportDialogFragment.java

/**
 * Collects references to the UI elements and binds click listeners
 *//*from  ww w . j  a  v a  2 s .com*/
private void bindViews() {
    View v = getView();
    mDestinationSpinner = (Spinner) v.findViewById(R.id.spinner_export_destination);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.export_destinations, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mDestinationSpinner.setAdapter(adapter);

    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    mExportAllCheckBox = (CheckBox) v.findViewById(R.id.checkbox_export_all);
    mExportAllCheckBox
            .setChecked(sharedPrefs.getBoolean(getString(R.string.key_export_all_transactions), false));

    mDeleteAllCheckBox = (CheckBox) v.findViewById(R.id.checkbox_post_export_delete);
    mDeleteAllCheckBox.setChecked(
            sharedPrefs.getBoolean(getString(R.string.key_delete_transactions_after_export), false));

    mSaveButton = (Button) v.findViewById(R.id.btn_save);
    mSaveButton.setText(R.string.btn_export);
    mCancelButton = (Button) v.findViewById(R.id.btn_cancel);

    mCancelButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });

    mSaveButton.setOnClickListener(new ExportClickListener());

    String defaultExportFormat = sharedPrefs.getString(getString(R.string.key_default_export_format),
            ExportFormat.QIF.name());
    mExportFormat = ExportFormat.valueOf(defaultExportFormat);
    View.OnClickListener clickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onRadioButtonClicked(view);
        }
    };

    RadioButton ofxRadioButton = (RadioButton) v.findViewById(R.id.radio_ofx_format);
    ofxRadioButton.setChecked(defaultExportFormat.equalsIgnoreCase(ExportFormat.OFX.name()));
    ofxRadioButton.setOnClickListener(clickListener);

    RadioButton qifRadioButton = (RadioButton) v.findViewById(R.id.radio_qif_format);
    qifRadioButton.setChecked(defaultExportFormat.equalsIgnoreCase(ExportFormat.QIF.name()));
    qifRadioButton.setOnClickListener(clickListener);
}

From source file:mx.openpay.android.example.AddCardActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.activity_add_card);

    this.progressFragment = ProgressDialogFragment.newInstance(R.string.progress_message);

    FragmentManager fm = this.getFragmentManager();
    this.deviceIdFragment = (DeviceIdFragment) fm.findFragmentByTag("DeviceCollector");
    // If not retained (or first time running), we need to create it.
    if (this.deviceIdFragment == null) {
        this.deviceIdFragment = new DeviceIdFragment();
        fm.beginTransaction().add(this.deviceIdFragment, "DeviceCollector").commit();
    }//  w ww .jav a 2  s  .c o m
    final RadioButton radio1 = (RadioButton) this.findViewById(R.id.radioButton1);
    radio1.setChecked(true);

}