Example usage for android.widget RadioGroup getChildAt

List of usage examples for android.widget RadioGroup getChildAt

Introduction

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

Prototype

public View getChildAt(int index) 

Source Link

Document

Returns the view at the specified position in the group.

Usage

From source file:com.cw.litenote.folder.FolderUi.java

public static void addNewFolder(final AppCompatActivity act, final int newTableId,
        final SimpleDragSortCursorAdapter folderAdapter) {
    // get folder name
    final String hintFolderName = act.getResources().getString(R.string.default_folder_name)
            .concat(String.valueOf(newTableId));

    // get layout inflater
    View rootView = act.getLayoutInflater().inflate(R.layout.add_new_folder, null);
    final TouchableEditText editFolderName = (TouchableEditText) rootView.findViewById(R.id.new_folder_name);

    // set cursor
    try {/*w w w  .  j a v a2 s .co  m*/
        Field f = TextView.class.getDeclaredField("mCursorDrawableRes");
        f.setAccessible(true);
        f.set(editFolderName, R.drawable.cursor);
    } catch (Exception ignored) {
    }

    // set hint
    editFolderName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                ((EditText) v).setHint(hintFolderName);
            }
        }
    });

    editFolderName.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ((EditText) v).setText(hintFolderName);
            ((EditText) v).setSelection(hintFolderName.length());
            v.performClick();
            return false;
        }
    });

    // radio buttons
    final RadioGroup mRadioGroup = (RadioGroup) rootView.findViewById(R.id.radioGroup_new_folder_at);

    // get new folder location option
    mPref_add_new_folder_location = act.getSharedPreferences("add_new_folder_option", 0);
    if (mPref_add_new_folder_location.getString("KEY_ADD_NEW_FOLDER_TO", "bottom").equalsIgnoreCase("top")) {
        mRadioGroup.check(mRadioGroup.getChildAt(0).getId());
        mAddFolderAt = 0;
    } else if (mPref_add_new_folder_location.getString("KEY_ADD_NEW_FOLDER_TO", "bottom")
            .equalsIgnoreCase("bottom")) {
        mRadioGroup.check(mRadioGroup.getChildAt(1).getId());
        mAddFolderAt = 1;
    }

    // update new folder location option
    mRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup RG, int id) {
            mAddFolderAt = mRadioGroup.indexOfChild(mRadioGroup.findViewById(id));
            if (mAddFolderAt == 0) {
                mPref_add_new_folder_location.edit().putString("KEY_ADD_NEW_FOLDER_TO", "top").apply();
            } else if (mAddFolderAt == 1) {
                mPref_add_new_folder_location.edit().putString("KEY_ADD_NEW_FOLDER_TO", "bottom").apply();
            }
        }
    });

    // set view to dialog
    Builder builder1 = new Builder(act);
    builder1.setView(rootView);
    final AlertDialog dialog1 = builder1.create();
    dialog1.show();

    // cancel button
    Button btnCancel = (Button) rootView.findViewById(R.id.new_folder_cancel);
    btnCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog1.dismiss();
        }
    });

    // add button
    Button btnAdd = (Button) rootView.findViewById(R.id.new_folder_add);
    btnAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DB_drawer db_drawer = new DB_drawer(act);

            String folderTitle;
            if (!Util.isEmptyString(editFolderName.getText().toString()))
                folderTitle = editFolderName.getText().toString();
            else
                folderTitle = act.getResources().getString(R.string.default_folder_name)
                        .concat(String.valueOf(newTableId));

            MainAct.mFolderTitles.add(folderTitle);
            // insert new drawer Id and Title
            db_drawer.insertFolder(newTableId, folderTitle, true);

            // insert folder table
            db_drawer.insertFolderTable(newTableId, true);

            // insert initial page table after Add new folder
            if (Define.INITIAL_PAGES_COUNT > 0) {
                for (int i = 1; i <= Define.INITIAL_PAGES_COUNT; i++) {
                    DB_folder dB_folder = new DB_folder(act, newTableId);
                    int style = Util.getNewPageStyle(act);
                    dB_folder.insertPage(DB_folder.getFocusFolder_tableName(), Define.getTabTitle(act, 1), i,
                            style, true);

                    dB_folder.insertPageTable(dB_folder, newTableId, i, true);
                }
            }

            // add new folder to the top
            if (mAddFolderAt == 0) {
                int startCursor = db_drawer.getFoldersCount(true) - 1;
                int endCursor = 0;

                //reorder data base storage for ADD_NEW_TO_TOP option
                int loop = Math.abs(startCursor - endCursor);
                for (int i = 0; i < loop; i++) {
                    swapFolderRows(startCursor, endCursor);
                    if ((startCursor - endCursor) > 0)
                        endCursor++;
                    else
                        endCursor--;
                }

                // update focus folder position
                if (db_drawer.getFoldersCount(true) == 1)
                    setFocus_folderPos(0);
                else
                    setFocus_folderPos(getFocus_folderPos() + 1);

                // update focus folder table Id for Add to top
                Pref.setPref_focusView_folder_tableId(act,
                        db_drawer.getFolderTableId(getFocus_folderPos(), true));

                // update playing highlight if needed
                if (BackgroundAudioService.mMediaPlayer != null)
                    MainAct.mPlaying_folderPos++;
            }

            // recover focus folder table Id
            DB_folder.setFocusFolder_tableId(Pref.getPref_focusView_folder_tableId(act));

            folderAdapter.notifyDataSetChanged();

            //end
            dialog1.dismiss();
            updateFocus_folderPosition();

            MainAct.mAct.invalidateOptionsMenu();
        }
    });
}

From source file:com.lauren.simplenews.view.MainBottomTab.java

@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
    if (this.viewPager != null) {
        for (int i = 0; i < group.getChildCount(); i++) {
            if (group.getChildAt(i).getId() == checkedId) {
                this.viewPager.setCurrentItem(i, false);
            }/*from w  w w. ja  v a  2 s .c o  m*/
        }
    }
}

From source file:cn.ieclipse.af.demo.common.ui.MainBottomTab.java

@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
    if (this.viewPager != null) {
        for (int i = 0; i < group.getChildCount(); i++) {
            if (group.getChildAt(i).getId() == checkedId) {
                this.viewPager.setCurrentItem(i, true);
            }/*from   w  w w  .ja v  a2  s  .  c o  m*/
        }
    }
}

From source file:com.mifos.mifosxdroid.online.SurveyQuestionFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_survey_question, container, false);
    ButterKnife.inject(this, view);
    thiscontext = container.getContext();
    mQuestionDatas = (new Gson()).fromJson(getArguments().getString(QUESTION_DATA), QuestionDatas.class);
    mScorecardValues = new ScorecardValues();

    tv_question.setText(mQuestionDatas.getText());

    ViewGroup hourButtonLayout = (ViewGroup) view.findViewById(R.id.radio1);
    for (int i = 0; i < mQuestionDatas.getResponseDatas().size(); i++) {
        button1 = new RadioButton(thiscontext);
        button1.setId(i);/*from   ww w.j av  a 2  s . c om*/
        button1.setText(mQuestionDatas.getResponseDatas().get(i).getText());
        hourButtonLayout.addView(button1);
        radioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            public void onCheckedChanged(RadioGroup mRadioGroup2, int checkedId2) {
                for (int j = 0; j < mRadioGroup2.getChildCount(); j++) {
                    btn = (RadioButton) mRadioGroup2.getChildAt(j);
                    int t = mRadioGroup2.getId();
                    Log.d(LOG_TAG, "" + t);

                    if (btn.getId() == checkedId2) {
                        answer = btn.getText().toString();
                        mScorecardValues.setQuestionId(mQuestionDatas.getQuestionId());
                        mScorecardValues
                                .setResponseId(mQuestionDatas.getResponseDatas().get(j).getResponseId());
                        mScorecardValues.setValue(mQuestionDatas.getResponseDatas().get(j).getValue());
                        mCallback.answer(mScorecardValues);
                        Log.d(LOG_TAG,
                                "Q R V" + mQuestionDatas.getQuestionId() + " "
                                        + mQuestionDatas.getResponseDatas().get(j).getResponseId() + " "
                                        + mQuestionDatas.getResponseDatas().get(j).getValue());
                        return;
                    }
                }
            }
        });
    }

    return view;
}

From source file:com.sweetiepiggy.littlepro.QuestionFragment.java

public void onSubmit(String correctAnswer) {
    mSubmitted = true;//from ww w.j  a v  a2s  .co m
    View view = getView();
    if (view != null) {
        view.findViewById(R.id.answer).setEnabled(false);

        RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.answerRadioGroup);
        for (int i = 0; i < radioGroup.getChildCount(); ++i) {
            radioGroup.getChildAt(i).setEnabled(false);
        }
    }
}

From source file:fi.tuukka.weather.view.FragmentStations.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.asemat, container, false);
    rg = (RadioGroup) view.findViewById(R.id.radioGroup1);
    rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override/*w  w  w .ja  v a  2 s  . c om*/
        public void onCheckedChanged(RadioGroup rg, int id) {
            if (listenCheck) {
                for (int i = 0; i < rg.getChildCount(); i++) {
                    RadioButton btn = (RadioButton) rg.getChildAt(i);
                    if (btn.getId() == id) {
                        String text = (String) btn.getText();
                        Station station = new Station(text, null);
                        changeStation(station);
                        refreshStations();
                        return;
                    }
                }
            }
        }
    });
    EditText searchBox = (EditText) view.findViewById(R.id.stationSearchBox);
    searchBox.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            String string = s.toString();
            if (query == null || !query.equals(string)) {
                query = s.toString();
                stationStrings = null; // mark as not finished
                ((ActivityMain) getActivity()).queryStations();
            }
        }
    });
    Activity activity = getActivity();
    header = (TextView) view.findViewById(R.id.stationsHeader);
    int fontsize = Utils.getScaledFont(activity);
    int pad = Utils.dpToPx(5, activity);
    header.setTextAppearance(activity, R.style.TextStyle);
    header.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontsize);
    header.setPadding(0, pad, 0, pad);
    header.setText("Syt kunta/kunnanosa:");
    super.onCreateView(inflater, container, savedInstanceState);
    return view;
}

From source file:com.odoo.base.login_signup.SyncWizard.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // handle item selection

    switch (item.getItemId()) {
    case R.id.menu_start_application:
        for (CheckBox chkBox : checkbox) {
            if (chkBox != null) {
                String authority = authorities.get(chkBox.getId() + "").toString();
                scope.main().setAutoSync(authority, chkBox.isChecked());
                scope.main().cancelSync(authority);
            }/*from   w w  w .j  a v a  2s. co  m*/
        }
        for (RadioGroup rdoGrp : rdoGroups) {
            if (rdoGrp != null) {
                for (int i = 0; i < rdoGrp.getChildCount(); i++) {
                    RadioButton rdoBtn = (RadioButton) rdoGrp.getChildAt(i);
                    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(scope.context());
                    Editor editor = settings.edit();
                    // TODO: store preference setting for your options.
                    editor.commit();
                    String authority = authorities.get(rdoBtn.getId() + "");
                    scope.main().setAutoSync(authority, rdoBtn.isChecked());
                    scope.main().cancelSync(authority);
                }
            }
        }
        getActivity().finish();
        getActivity().startActivity(getActivity().getIntent());
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.openerp.base.login.SyncWizard.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // handle item selection

    int itemId = item.getItemId();
    if (itemId == R.id.menu_start_application) {
        for (CheckBox chkBox : checkbox) {
            if (chkBox != null) {
                String authority = authorities.get(chkBox.getId() + "").toString();
                scope.main().setAutoSync(authority, chkBox.isChecked());
                scope.main().cancelSync(authority);
            }/*from   ww  w  . j a  v a  2 s.c om*/
        }
        for (RadioGroup rdoGrp : rdoGroups) {
            if (rdoGrp != null) {
                for (int i = 0; i < rdoGrp.getChildCount(); i++) {
                    RadioButton rdoBtn = (RadioButton) rdoGrp.getChildAt(i);
                    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(scope.context());
                    Editor editor = settings.edit();
                    //TODO: store preference setting for your options.
                    editor.commit();
                    String authority = authorities.get(rdoBtn.getId() + "");
                    scope.main().setAutoSync(authority, rdoBtn.isChecked());
                    scope.main().cancelSync(authority);
                }
            }
        }
        getActivity().finish();
        getActivity().startActivity(getActivity().getIntent());
        return true;
    } else {
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.keysolutions.meteorparties.PartyDetailFragment.java

/**
 * Updates current RSVP display/*ww w  .j ava2 s  .c  om*/
 * @param rootView root view holding all the fields
 */
@SuppressLint("NewApi")
public void updateMyRsvpDisplay(View rootView) {
    // add info about my RSVP
    boolean isLoggedIn = MyDDPState.getInstance().isLoggedIn();
    ((View) (rootView.findViewById(R.id.login_for_rsvp)))
            .setVisibility(isLoggedIn ? View.INVISIBLE : View.VISIBLE);
    ((View) (rootView.findViewById(R.id.rsvp_buttons)))
            .setVisibility(isLoggedIn ? View.VISIBLE : View.INVISIBLE);
    ((View) (rootView.findViewById(R.id.label_my_rsvp)))
            .setVisibility(isLoggedIn ? View.VISIBLE : View.INVISIBLE);

    if (isLoggedIn) {
        RadioGroup rsvpButtons = ((RadioGroup) rootView.findViewById(R.id.rsvp_buttons));
        rsvpButtons.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
                for (int j = 0; j < radioGroup.getChildCount(); j++) {
                    final ToggleButton view = (ToggleButton) radioGroup.getChildAt(j);
                    view.setChecked(view.getId() == checkedId);
                }
            }
        });
        ToggleButton btnYes = ((ToggleButton) rootView.findViewById(R.id.rsvp_yes));
        ToggleButton btnNo = ((ToggleButton) rootView.findViewById(R.id.rsvp_no));
        ToggleButton btnMaybe = ((ToggleButton) rootView.findViewById(R.id.rsvp_maybe));
        OnClickListener toggleListener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                onToggle(v);
            }
        };
        btnYes.setOnClickListener(toggleListener);
        btnNo.setOnClickListener(toggleListener);
        btnMaybe.setOnClickListener(toggleListener);
        String myRsvp = getMyRsvp();
        if (myRsvp != null) {
            if (myRsvp.equals("yes")) {
                rsvpButtons.check(R.id.rsvp_yes);
            } else if (myRsvp.equals("no")) {
                rsvpButtons.check(R.id.rsvp_no);
            } else if (myRsvp.equals("maybe")) {
                rsvpButtons.check(R.id.rsvp_maybe);
            }
        }

        // if we can, add button animation on Yes because it's cool
        if (android.os.Build.VERSION.SDK_INT > 11) {
            btnYes.animate().setDuration(200);
            btnYes.setOnTouchListener(new OnTouchListener() {
                @Override
                public boolean onTouch(View button, MotionEvent event) {
                    if (event.getAction() == MotionEvent.ACTION_DOWN) {
                        ((ToggleButton) button).animate().setInterpolator(sDecelerator).scaleX(.7f).scaleY(.7f);
                    } else {
                        ((ToggleButton) button).animate().setInterpolator(sOverShooter).scaleX(1f).scaleY(1f);
                    }
                    return false;
                }
            });
        }
    }
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout);/*from w  w w  . j  a  v a 2s  .  co m*/

    // Initialize the logging framework.
    initializeLogging();

    // Check if permissions are set, otherwise exit app.
    if (ActivityCompat.checkSelfPermission(this,
            android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

        Toast.makeText(MainActivity.this, "Please set ACCESS_FINE_LOCATION permission", Toast.LENGTH_LONG)
                .show();

        finish();
        return;
    }

    // Get selection from shared Preferences. The preference is set when selecting a radiobutton.
    // Then set the text in the editable field to the last selected text (currently a default text)
    mAppPrefs = new AppPreferences(getApplicationContext());

    RadioGroup rg = (RadioGroup) findViewById(R.id.whichSMS);

    RadioButton rb = (RadioButton) rg.getChildAt(mAppPrefs.SelectionId);
    rg.check(rb.getId());
    setText(mAppPrefs.SelectionId);

    // Create an instance of GoogleAPIClient.
    if (mGoogleApiClient == null) {
        mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this).addApi(LocationServices.API).build();
    }

    // Create a message handler
    // Currently not in use but keep for future projects.
    UIMsgHandler handler = new UIMsgHandler(TAG);

    // Register context menu for radio button group
    registerForContextMenu(rg);

    mReceiver = new MyBCreceiver();
}