Example usage for android.widget RadioGroup getCheckedRadioButtonId

List of usage examples for android.widget RadioGroup getCheckedRadioButtonId

Introduction

In this page you can find the example usage for android.widget RadioGroup getCheckedRadioButtonId.

Prototype

@IdRes
public int getCheckedRadioButtonId() 

Source Link

Document

Returns the identifier of the selected radio button in this group.

Usage

From source file:at.bitfire.davdroid.ui.CreateCalendarActivity.java

public void onCreateCollection(MenuItem item) {
    boolean ok = true;
    CollectionInfo info = new CollectionInfo();

    Spinner spinner = (Spinner) findViewById(R.id.home_sets);
    String homeSet = (String) spinner.getSelectedItem();

    EditText edit = (EditText) findViewById(R.id.display_name);
    info.displayName = edit.getText().toString();
    if (TextUtils.isEmpty(info.displayName)) {
        edit.setError(getString(R.string.create_collection_display_name_required));
        ok = false;/* w ww .  j a v a  2s  . c  o m*/
    }

    edit = (EditText) findViewById(R.id.description);
    info.description = StringUtils.trimToNull(edit.getText().toString());

    View view = findViewById(R.id.color);
    info.color = ((ColorDrawable) view.getBackground()).getColor();

    spinner = (Spinner) findViewById(R.id.time_zone);
    net.fortuna.ical4j.model.TimeZone tz = DateUtils.tzRegistry.getTimeZone((String) spinner.getSelectedItem());
    if (tz != null) {
        Calendar cal = new Calendar();
        cal.getComponents().add(tz.getVTimeZone());
        info.timeZone = cal.toString();
    }

    RadioGroup typeGroup = (RadioGroup) findViewById(R.id.type);
    switch (typeGroup.getCheckedRadioButtonId()) {
    case R.id.type_events:
        info.supportsVEVENT = true;
        break;
    case R.id.type_tasks:
        info.supportsVTODO = true;
        break;
    case R.id.type_events_and_tasks:
        info.supportsVEVENT = true;
        info.supportsVTODO = true;
        break;
    }

    if (ok) {
        info.type = CollectionInfo.Type.CALENDAR;
        info.url = HttpUrl.parse(homeSet).resolve(UUID.randomUUID().toString() + "/").toString();
        CreateCollectionFragment.newInstance(account, info).show(getSupportFragmentManager(), null);
    }
}

From source file:com.partypoker.poker.engagement.reach.activity.EngagementPollActivity.java

@Override
protected void onAction() {
    /* Scan U.I radio button states */
    LinearLayout questionsLayout = getView("questions");
    JSONArray questions = mContent.getQuestions();
    try {/*from   w w  w  .  ja va2s .  c o m*/
        for (int i = 0; i < questions.length(); i++) {
            /* Get question */
            JSONObject question = questions.getJSONObject(i);

            /* Get radio group by question */
            String questionId = question.getString("id");
            RadioGroup choicesView = (RadioGroup) questionsLayout.findViewWithTag(question);

            /* Get selected choice id */
            int selectedViewId = choicesView.getCheckedRadioButtonId();
            RadioButton selectedChoiceView = (RadioButton) choicesView.findViewById(selectedViewId);
            String choiceId = selectedChoiceView.getTag().toString();

            /* Fill answer */
            mContent.fillAnswer(questionId, choiceId);
        }
    } catch (JSONException jsone) {
        /* Won't happen */
    }

    /* Submit answers */
    mContent.actionContent(getApplicationContext());
}

From source file:com.github.johnpersano.supertoasts.demo.fragments.AttributeRadioGroupFragment.java

@Nullable
@Override/*ww w .  j  a  va 2s . c  o  m*/
@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.baozi.activity.NpcBusinessRegisterActivity.java

private void init() {
    mQueue = Volley.newRequestQueue(getApplicationContext());
    uuid = UUID.randomUUID();//from   w w w.j  a  v a2s.  c o m
    myHandler = new MyHandler();
    i = 0;
    flag = 1;

    zuzhimingcheng = (EditText) findViewById(R.id.zuzhimingcheng);
    zuzhidizhi = (EditText) findViewById(R.id.zuzhidizhi);
    zuzhiyoubian = (EditText) findViewById(R.id.zuzhiyoubian);
    zuzhidaima = (EditText) findViewById(R.id.zuzhidaima);
    jigouxingzhi = (RadioGroup) findViewById(R.id.jigouxingzhi);
    jigouxingzhi.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            //ID
            int radioButtonId = group.getCheckedRadioButtonId();
            //IDRadioButton
            RadioButton rb = (RadioButton) NpcBusinessRegisterActivity.this.findViewById(radioButtonId);
            xingzhi = rb.getText().toString();
        }
    });

    xingzhi = "";

    jingyingfanwei = (EditText) findViewById(R.id.jingyingfanwei);
    farenxingming = (EditText) findViewById(R.id.farenxingming);
    farenshenfenzhenghao = (EditText) findViewById(R.id.farenshenfenzhenghao);
    xingming = (EditText) findViewById(R.id.xingming);
    shoujihao = (EditText) findViewById(R.id.shoujihao);
    zhiwu = (EditText) findViewById(R.id.zhiwu);
    youxiang = (EditText) findViewById(R.id.youxiang);
    chuanzhen = (EditText) findViewById(R.id.chuanzhen);

    intent = new Intent(getApplicationContext(), MultiImageSelectorActivity.class);
    // 
    intent.putExtra(MultiImageSelectorActivity.EXTRA_SHOW_CAMERA, true);
    // 
    intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_MODE, 0);
    tianjiayingyezhizhao = (TextView) findViewById(R.id.tianjiayingyezhizhao);
    tianjiayingyezhizhao.setOnClickListener(this);
    yingyezhizhao = (ImageView) findViewById(R.id.yingyezhizhao);
    tianjiashenfenzheng = (TextView) findViewById(R.id.tianjiashenfenzheng);
    tianjiashenfenzheng.setOnClickListener(this);
    farenshenfenzhengzhao = (ImageView) findViewById(R.id.farenshenfenzhengzhao);

    zhuce = (Button) findViewById(R.id.zhuce);
    zhuce.setOnClickListener(this);
}

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

private void sendAction(View v) {
    Toast.makeText(getApplicationContext(), "Save Pressed", Toast.LENGTH_SHORT).show();

    ////www.j a  v a2 s.com
    // Check is nothing was requested
    //
    RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radioGroup1);
    if (radioGroup == null) {
        Toast.makeText(getApplicationContext(), "RadioGroup is null", Toast.LENGTH_SHORT).show();
        return;
    }

    int id = radioGroup.getCheckedRadioButtonId();
    if (id == -1) {
        Toast.makeText(getApplicationContext(), "No Action selected", Toast.LENGTH_SHORT).show();
        Intent i = getIntent();
        setResult(RESULT_CANCELED, i);
    }
    //
    // Check if Ignore was requested
    //
    else if (id == R.id.a0) {
        Toast.makeText(getApplicationContext(), "Ignore requested", Toast.LENGTH_SHORT).show();
        Intent i = getIntent();
        message.setMessageType("33");
        message.setActionList("A0");
        i.putExtra("MESSAGE", this.message);
        setResult(RESULT_OK, i);
    }
    //
    // Check if Log was requested
    //
    else if (id == R.id.a1) {
        Toast.makeText(getApplicationContext(), "Log requested", Toast.LENGTH_SHORT).show();
        Intent i = getIntent();
        message.setMessageType("33");
        message.setActionList("A1");
        i.putExtra("MESSAGE", this.message);
        setResult(RESULT_OK, i);
    }

    finish();
}

From source file:com.physphil.android.unitconverterultimate.fragments.ConversionFragment.java

/**
 * Get the Unit associated with the checked button in a radio group
 *
 * @param group RadioGroup which contains the button
 * @return Unit associated with checked button
 *//*from  w w w.j av  a 2s  . co m*/
private Unit getCheckedUnit(RadioGroup group) {
    int index = group.getCheckedRadioButtonId();
    RadioButton btn = (RadioButton) group.findViewById(index);
    return (Unit) btn.getTag();
}

From source file:com.bonsai.wallet32.RestoreWalletActivity.java

public void restoreWallet(View view) {
    mLogger.info("restore wallet");

    NetworkParameters params = Constants.getNetworkParameters(getApplicationContext());

    String filePrefix = "wallet32";

    EditText hextxt = (EditText) findViewById(R.id.seed);
    EditText mnemonictxt = (EditText) findViewById(R.id.mnemonic);

    String hexseedstr = hextxt.getText().toString();
    String mnemonicstr = mnemonictxt.getText().toString();

    // Did the user specify *both* hex seed and mnemonic?
    if (hexseedstr.length() > 0 && mnemonicstr.length() > 0) {
        showErrorDialog(mRes.getString(R.string.restore_bothbad));
        return;// w w  w  . j  av a2s.  co m
    }

    byte[] seed;

    // Did we have a hex seed?
    if (hexseedstr.length() > 0) {
        try {
            seed = Hex.decode(hexseedstr);
        } catch (Exception ex) {
            showErrorDialog(mRes.getString(R.string.restore_badhexvalue));
            return;
        }
        if (seed.length % 8 > 0) {
            showErrorDialog(mRes.getString(R.string.restore_badhexlength));
            return;
        }
    }

    // How about a mnemonic string?
    else if (mnemonicstr.length() > 0) {
        MnemonicCodeX mc;
        try {
            InputStream wis = getApplicationContext().getAssets().open("wordlist/english.txt");
            mc = new MnemonicCodeX(wis, MnemonicCodeX.BIP39_ENGLISH_SHA256);
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }
        List<String> words = new ArrayList<String>(Arrays.asList(mnemonicstr.trim().split("\\s+")));
        try {
            seed = mc.toEntropy(words);
        } catch (MnemonicException.MnemonicLengthException ex) {
            showErrorDialog(mRes.getString(R.string.restore_badlength));
            return;
        } catch (MnemonicException.MnemonicWordException ex) {
            String msg = mRes.getString(R.string.restore_badword, ex.badWord);
            showErrorDialog(msg);
            return;
        } catch (MnemonicException.MnemonicChecksumException ex) {
            showErrorDialog(mRes.getString(R.string.restore_badchecksum));
            return;
        }
    }

    // Hmm, nothing specified?
    else {
        showErrorDialog(mRes.getString(R.string.restore_noseed));
        return;
    }

    EditText ppEditText = (EditText) findViewById(R.id.passphrase);
    String passphrase = ppEditText.getText().toString();

    // How many accounts to restore?
    int numaccts;
    try {
        EditText numacctedittxt = (EditText) findViewById(R.id.numaccounts);
        String numacctsstr = numacctedittxt.getText().toString();
        numaccts = Integer.parseInt(numacctsstr);
    } catch (NumberFormatException ex) {
        showErrorDialog(mRes.getString(R.string.restore_badnumaccts));
        return;
    }

    MnemonicCodeX.Version bip39version;
    HDStructVersion hdsv;
    RadioGroup hdsrg = (RadioGroup) findViewById(R.id.format_choice);
    switch (hdsrg.getCheckedRadioButtonId()) {
    default:
    case R.id.format_v0_5:
        hdsv = HDWallet.HDStructVersion.HDSV_STDV1;
        bip39version = MnemonicCodeX.Version.V0_6;
        break;
    case R.id.format_v0_4:
        hdsv = HDWallet.HDStructVersion.HDSV_STDV0;
        bip39version = MnemonicCodeX.Version.V0_6;
        break;
    case R.id.format_v0_3:
        hdsv = HDWallet.HDStructVersion.HDSV_L0PRV;
        bip39version = MnemonicCodeX.Version.V0_6;
        break;
    case R.id.format_v0_2:
        hdsv = HDWallet.HDStructVersion.HDSV_L0PUB;
        bip39version = MnemonicCodeX.Version.V0_6;
        break;
    case R.id.format_v0_1:
        hdsv = HDWallet.HDStructVersion.HDSV_L0PUB;
        bip39version = MnemonicCodeX.Version.V0_5;
        break;
    }

    WalletApplication wallapp = (WalletApplication) getApplicationContext();

    // Setup a wallet with the restore seed.
    HDWallet hdwallet = new HDWallet(wallapp, params, wallapp.mKeyCrypter, wallapp.mAesKey, seed, passphrase,
            numaccts, bip39version, hdsv);
    hdwallet.persist(wallapp);

    // Spin up the WalletService.
    Intent svcintent = new Intent(this, WalletService.class);
    Bundle bundle = new Bundle();
    bundle.putString("SyncState", "RESTORE");
    svcintent.putExtras(bundle);
    startService(svcintent);

    Intent intent = new Intent(this, MainActivity.class);
    startActivity(intent);

    // Prevent the user from coming back here.
    finish();
}

From source file:org.phillyopen.mytracks.cyclephilly.UserInfoActivity.java

private void savePreferences() {
    // Save user preferences. We need an Editor object to
    // make changes. All objects are from android.context.Context
    final SharedPreferences settings = getSharedPreferences("PREFS", 0);
    SharedPreferences.Editor editor = settings.edit();

    editor.putInt("" + PREF_AGE, ((Spinner) findViewById(R.id.ageSpinner)).getSelectedItemPosition());
    editor.putInt("" + PREF_ETHNICITY,
            ((Spinner) findViewById(R.id.ethnicitySpinner)).getSelectedItemPosition());
    editor.putInt("" + PREF_INCOME, ((Spinner) findViewById(R.id.incomeSpinner)).getSelectedItemPosition());
    editor.putInt("" + PREF_RIDERTYPE,
            ((Spinner) findViewById(R.id.ridertypeSpinner)).getSelectedItemPosition());
    editor.putInt("" + PREF_RIDERHISTORY,
            ((Spinner) findViewById(R.id.riderhistorySpinner)).getSelectedItemPosition());

    editor.putString("" + PREF_ZIPHOME, ((EditText) findViewById(R.id.TextZipHome)).getText().toString());
    editor.putString("" + PREF_ZIPWORK, ((EditText) findViewById(R.id.TextZipWork)).getText().toString());
    editor.putString("" + PREF_ZIPSCHOOL, ((EditText) findViewById(R.id.TextZipSchool)).getText().toString());
    editor.putString("" + PREF_EMAIL, ((EditText) findViewById(R.id.TextEmail)).getText().toString());
    editor.putInt("" + PREF_CYCLEFREQ, ((SeekBar) findViewById(R.id.SeekCycleFreq)).getProgress());

    //Anon ID creator
    String anon = settings.getString("" + PREF_ANONID, "NADA");
    if (anon == "NADA") {

        editor.putString("" + PREF_ANONID, randomString(CHARSET_AZ_09, 8));
    }/*from w  w  w.  ja  v a2s .com*/

    RadioGroup rbg = (RadioGroup) findViewById(R.id.RadioGroup01);
    if (rbg.getCheckedRadioButtonId() == R.id.ButtonMale) {
        editor.putInt("" + PREF_GENDER, 2);
        //Log.v(TAG, "gender=" + 2);
    }
    if (rbg.getCheckedRadioButtonId() == R.id.ButtonFemale) {
        editor.putInt("" + PREF_GENDER, 1);
        //Log.v(TAG, "gender=" + 1);
    }

    //      Log.v(TAG,
    //            "ageIndex="
    //                  + ((Spinner) findViewById(R.id.ageSpinner))
    //                        .getSelectedItemPosition());
    //      Log.v(TAG,
    //            "ethnicityIndex="
    //                  + ((Spinner) findViewById(R.id.ethnicitySpinner))
    //                        .getSelectedItemPosition());
    //      Log.v(TAG,
    //            "incomeIndex="
    //                  + ((Spinner) findViewById(R.id.incomeSpinner))
    //                        .getSelectedItemPosition());
    //      Log.v(TAG,
    //            "ridertypeIndex="
    //                  + ((Spinner) findViewById(R.id.ridertypeSpinner))
    //                        .getSelectedItemPosition());
    //      Log.v(TAG,
    //            "riderhistoryIndex="
    //                  + ((Spinner) findViewById(R.id.riderhistorySpinner))
    //                        .getSelectedItemPosition());
    //      Log.v(TAG, "ziphome="
    //            + ((EditText) findViewById(R.id.TextZipHome)).getText()
    //                  .toString());
    //      Log.v(TAG, "zipwork="
    //            + ((EditText) findViewById(R.id.TextZipWork)).getText()
    //                  .toString());
    //      Log.v(TAG, "zipschool="
    //            + ((EditText) findViewById(R.id.TextZipSchool)).getText()
    //                  .toString());
    //      Log.v(TAG, "email="
    //            + ((EditText) findViewById(R.id.TextEmail)).getText()
    //                  .toString());
    //      Log.v(TAG,
    //            "frequency="
    //                  + ((SeekBar) findViewById(R.id.SeekCycleFreq))
    //                        .getProgress() / 100);

    // Don't forget to commit your edits!!!
    editor.commit();
    //Update firebase
    final Firebase ref = new Firebase(FIRE_REF);
    String deviceName = android.os.Build.MODEL;
    String deviceMan = android.os.Build.MANUFACTURER;
    Map<String, Object> payload = new HashMap<String, Object>();
    payload.put("email", ((EditText) findViewById(R.id.TextEmail)).getText().toString());
    payload.put("device", deviceName);

    payload.put("uid", settings.getString("" + PREF_ANONID, "anon"));
    System.out.println("uid: " + settings.getString("" + PREF_ANONID, "anon"));

    JSONObject pl = new JSONObject(payload);
    TokenGenerator tokenGenerator = new TokenGenerator(FIRE_TOKEN);
    String token = tokenGenerator.createToken(pl);

    //Re-authenticate
    ref.unauth();
    ref.authWithCustomToken(token, new Firebase.AuthResultHandler() {
        @Override
        public void onAuthenticationError(FirebaseError error) {
            System.err.println("Login Failed! " + error.getMessage());
        }

        @Override
        public void onAuthenticated(AuthData authData) {
            System.out.println("Login Succeeded: ! " + authData.getAuth().get("uid"));
            Map<String, String> map = new HashMap<String, String>();
            map.put("provider", authData.getProvider());
            map.put("lastLogin", "" + System.currentTimeMillis());
            if (authData.getAuth().containsKey("email")) {
                map.put("email", authData.getAuth().get("email").toString());
            }
            if (authData.getAuth().containsKey("device")) {
                map.put("device", authData.getAuth().get("device").toString());
            }
            String gender = "unknown";
            if (settings.getInt("" + PREF_GENDER, 0) == 2) {
                gender = "male";
            } else if (settings.getInt("" + PREF_GENDER, 0) == 1) {
                gender = "female";
            }
            map.put("gender", gender);
            ref.child("users").child(authData.getAuth().get("uid").toString()).setValue(map);
        }
    });

    Toast.makeText(getBaseContext(), "User preferences saved.", Toast.LENGTH_SHORT).show();
}

From source file:com.tbay.android.FrequentSMS.MainActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
    case R.id.edit:
        //editNote(info.id);
        return true;
    case R.id.show:
        RadioGroup rg = (RadioGroup) findViewById(R.id.whichSMS);
        int rbid = rg.getCheckedRadioButtonId();

        RadioButton rb = (RadioButton) findViewById(rbid);

        int position = rg.indexOfChild(rb);

        Toast.makeText(MainActivity.this, "Telefon nummer: " + Integer.toString(position), Toast.LENGTH_LONG)
                .show();//from  ww  w  . j ava 2  s  . c  o  m
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:com.tbay.android.FrequentSMS.MainActivity.java

public void sendSMS(View view) {

    EditText Txt = (EditText) findViewById(R.id.SMSText);

    RadioGroup rg = (RadioGroup) findViewById(R.id.whichSMS);
    int rbid = rg.getCheckedRadioButtonId();

    SmsManager smsManager = SmsManager.getDefault();

    switch (rbid) {
    case R.id.Wifi:
        mAppPrefs.Key1_Msg = Txt.getText().toString();
        mAppPrefs.SelectionId = 0;//from   w  w  w  .j  a  v a 2  s .  co m
        smsManager.sendTextMessage(AppConstants.phoneWifi, null, mAppPrefs.Key1_Msg, null, null);
        break;
    case R.id.Aftensmad:
        mAppPrefs.Key2_Msg = Txt.getText().toString();
        mAppPrefs.SelectionId = 1;
        smsManager.sendTextMessage(AppConstants.phoneAnnette, null, mAppPrefs.Key2_Msg, null, null);
        break;
    case R.id.Snart_hjemme:
        mAppPrefs.Key3_Msg = Txt.getText().toString();
        mAppPrefs.SelectionId = 2;
        smsManager.sendTextMessage(AppConstants.phoneAnnette, null, mAppPrefs.Key3_Msg, null, null);
        break;
    case R.id.TestSMS:
        mAppPrefs.Key4_Msg = Txt.getText().toString();
        mAppPrefs.SelectionId = 3;
        smsManager.sendTextMessage(AppConstants.phonePrivate, null, mAppPrefs.Key4_Msg, null, null);
        break;
    }
    mAppPrefs.savePreferences(getApplicationContext());
}