Example usage for android.widget RadioGroup setOnCheckedChangeListener

List of usage examples for android.widget RadioGroup setOnCheckedChangeListener

Introduction

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

Prototype

public void setOnCheckedChangeListener(OnCheckedChangeListener listener) 

Source Link

Document

Register a callback to be invoked when the checked radio button changes in this group.

Usage

From source file:dynamite.zafroshops.app.fragment.ReviewDialogFragment.java

@NonNull
@Override/*  w w w.ja va2s. co  m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    rating = 0;
    zopID = getArguments().getString(DIALOG_ZOP_ID);
    location = (Location) getArguments().getSerializable(DIALOG_ZOP_LOCATION);

    Activity activity = getActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    LayoutInflater inflater = activity.getLayoutInflater();
    final View view = inflater.inflate(R.layout.review_dialog, null);

    builder.setView(view).setTitle(R.string.app_name)
            .setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    MobileConfirmation confirmation = new MobileConfirmation();
                    Boolean confirmed = false;
                    int id = ((RadioGroup) view.findViewById(R.id.review_confirmation_group))
                            .getCheckedRadioButtonId();

                    if (id == view.findViewById(R.id.review_confirmation_know).getId()) {
                        confirmed = true;
                    } else if (id == view.findViewById(R.id.review_confirmation_been).getId()) {
                        confirmed = false;
                    }

                    confirmation.ZopID = Integer.parseInt(zopID);
                    confirmation.Comments = ((EditText) view.findViewById(R.id.review_comments)).getText()
                            .toString();
                    confirmation.Confirmed = confirmed;
                    confirmation.ConfirmedBy = "Android";
                    confirmation.ConfirmedDate = Calendar.getInstance().getTime();
                    confirmation.Rating = rating;

                    // submit
                    ListenableFuture<JsonElement> result = MainActivity.MobileClient
                            .invokeApi("mobileConfirmation", confirmation, JsonElement.class);
                    Futures.addCallback(result, new FutureCallback<JsonElement>() {
                        @Override
                        public void onSuccess(JsonElement result) {
                            ((MenuItem) view.findViewById(R.id.menu_zop_review)).setEnabled(false);
                        }

                        @Override
                        public void onFailure(@NonNull Throwable t) {

                        }
                    });
                }
            }).setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            });

    RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.review_confirmation_group);

    view.findViewById(R.id.review_rating).setVisibility(View.INVISIBLE);
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId == R.id.review_confirmation_been) {
                view.findViewById(R.id.review_rating).setVisibility(View.VISIBLE);
            } else {
                view.findViewById(R.id.review_rating).setVisibility(View.INVISIBLE);
            }
        }
    });

    return builder.create();
}

From source file:com.bellman.bible.android.view.activity.search.Search.java

/**
 * Called when the activity is first created.
 *///from   ww  w . j  av  a2  s .  c  o  m
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, true);
    Log.i(TAG, "Displaying Search view");
    setContentView(R.layout.search);

    if (!searchControl.validateIndex(getDocumentToSearch())) {
        Dialogs.getInstance().showErrorMsg(R.string.error_occurred, new Callback() {
            @Override
            public void okay() {
                finish();
            }
        });
    }

    mSearchTextInput = (EditText) findViewById(R.id.searchText);
    mSearchTextInput.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                // Perform action on key press
                onSearch(null);
                return true;
            }
            return false;
        }
    });

    // pre-load search string if passed in
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        String searchText = extras.getString(SEARCH_TEXT_SAVE);
        if (StringUtils.isNotEmpty(searchText)) {
            mSearchTextInput.setText(searchText);
        }
    }

    RadioGroup wordsRadioGroup = (RadioGroup) findViewById(R.id.wordsGroup);
    wordsRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            wordsRadioSelection = checkedId;
        }
    });
    if (extras != null) {
        int wordsSelection = extras.getInt(WORDS_SELECTION_SAVE, -1);
        if (wordsSelection != -1) {
            wordsRadioGroup.check(wordsSelection);
        }
    }

    RadioGroup sectionRadioGroup = (RadioGroup) findViewById(R.id.bibleSectionGroup);
    sectionRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            sectionRadioSelection = checkedId;
        }
    });
    if (extras != null) {
        int sectionSelection = extras.getInt(SECTION_SELECTION_SAVE, -1);
        if (sectionSelection != -1) {
            sectionRadioGroup.check(sectionSelection);
        }
    }

    // set text for current bible book on appropriate radio button
    RadioButton currentBookRadioButton = (RadioButton) findViewById(R.id.searchCurrentBook);

    // set current book to default and allow override if saved - implies returning via Back button
    currentBookName = searchControl.getCurrentBookName();
    if (extras != null) {
        String currentBibleBookSaved = extras.getString(CURRENT_BIBLE_BOOK_SAVE);
        if (currentBibleBookSaved != null) {
            currentBookName = currentBibleBookSaved;
        }
    }
    currentBookRadioButton.setText(currentBookName);

    Log.d(TAG, "Finished displaying Search view");
}

From source file:com.kyakujin.android.autoeco.ui.SilentModeSettingFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    mActivity = getActivity();//  w  w  w .j a v  a  2  s .  c  o m
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.fragment_dialog_silentmode, null, false);
    RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.radioGroupSilentMode);

    // ?????????
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            switch (checkedId) {
            case R.id.radioNormal:
                mSilentMode = AudioManager.RINGER_MODE_NORMAL;
                break;
            case R.id.radioSilent:
                mSilentMode = AudioManager.RINGER_MODE_SILENT;
                break;
            case R.id.radioVibrate:
                mSilentMode = AudioManager.RINGER_MODE_VIBRATE;
                break;
            default:
            }
        }
    });

    mCurrentEcoId = getArguments().getInt(Conf.SHARED_ECOID);
    mSilentMode = getArguments().getInt(Conf.SHARED_SILENTMODE);

    switch (mSilentMode) {
    case AudioManager.RINGER_MODE_NORMAL:
        radioGroup.check(R.id.radioNormal);
        break;
    case AudioManager.RINGER_MODE_SILENT:
        radioGroup.check(R.id.radioSilent);
        break;
    case AudioManager.RINGER_MODE_VIBRATE:
        radioGroup.check(R.id.radioVibrate);
        break;
    default:
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.setting_silent);
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            EcoDAO dao = new EcoDAO(mActivity);
            dao.updateSilentMode(mCurrentEcoId, mSilentMode);
        }
    });
    builder.setNegativeButton("Cancel", null);
    builder.setView(view);

    return builder.create();

}

From source file:net.sarangnamu.home.MainActivity.java

private void initMenu() {
    group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override/*from ww  w  .java 2s  . c  om*/
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            Navigator nv = Navigator.getInstance(MainActivity.this);

            switch (checkedId) {
            case R.id.mnu_home:
                nv.resetAdd(R.id.content, HomeFrgmt.class);
                break;

            case R.id.mnu_study:
                nv.resetAdd(R.id.content, StudyFrgmt.class);
                break;

            case R.id.mnu_qna:
                nv.resetAdd(R.id.content, QnaFrgmt.class);
                break;
            }

            sliding.closePane();
        }
    });

    FontLoader.getInstance(MainActivity.this).applyChild("Ubuntu-L", group, RadioButton.class);
}

From source file:com.kyakujin.android.autoeco.ui.SleepSettingFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    mActivity = getActivity();/*from   w  w w  .j  av a2 s  .  c  o  m*/
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.fragment_dialog_sleep, null, false);
    RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.radioGroupSleep);

    // ?????????
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            switch (checkedId) {
            case R.id.radioTime1:
                mSleepTime = SleepTime.TIME1;
                break;
            case R.id.radioTime2:
                mSleepTime = SleepTime.TIME2;
                break;
            case R.id.radioTime3:
                mSleepTime = SleepTime.TIME3;
                break;
            case R.id.radioTime4:
                mSleepTime = SleepTime.TIME4;
                break;
            case R.id.radioTime5:
                mSleepTime = SleepTime.TIME5;
                break;
            case R.id.radioTime6:
                mSleepTime = SleepTime.TIME6;
                break;
            default:
            }
        }
    });

    mCurrentEcoId = getArguments().getInt(Conf.SHARED_ECOID);
    mSleepTime = Conf.mapSleepTime.get(getArguments().getInt(Conf.SHARED_SLEEPTIME_ORDINAL));

    // ?
    setDefaultRadioButton(radioGroup);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.setting_sleep);
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            EcoDAO dao = new EcoDAO(mActivity);
            dao.updateSleepTime(mCurrentEcoId, mSleepTime.ordinal());
        }
    });
    builder.setNegativeButton("Cancel", null);
    builder.setView(view);

    return builder.create();

}

From source file:com.qasp.diego.arsp.homeFrag.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    RadioGroup rgroup_avaliacao;
    Button button_enviar;//ww  w. j av  a 2 s. c  o m

    final View rootview = inflater.inflate(R.layout.fragment_home, container, false);
    rgroup_avaliacao = (RadioGroup) rootview.findViewById(R.id.radio_avaliacao);
    rgroup_avaliacao.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            switch (checkedId) {
            case R.id.radiobom:
                avaliacao_escolhida = "Bom";
                break;
            case R.id.radiook:
                avaliacao_escolhida = "OK";
                break;
            case R.id.radioruim:
                avaliacao_escolhida = "Ruim";
                break;
            }
            Log.d("avaliacao_escolhida", avaliacao_escolhida);
        }
    });

    button_enviar = (Button) rootview.findViewById(R.id.benviar);
    button_enviar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Usuario nao escolheu uma avaliacao. Mostrar Dialogo de Erro.
            if (avaliacao_escolhida == null) {
                AlertDialog.Builder erro = new AlertDialog.Builder(v.getContext());
                erro.setMessage("Voc deve selecionar uma Avaliao.");
                erro.setCancelable(true);
                erro.setNeutralButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
                AlertDialog alerta = erro.create();
                alerta.show();
            } else {
                Intent i = new Intent(Intent.ACTION_SEND);
                i.setType("message/rfc822");
                i.putExtra(Intent.EXTRA_EMAIL, new String[] { "iqspsuporte@gmail.com" });
                i.putExtra(Intent.EXTRA_SUBJECT, "ArSP - Feedback" + " (" + avaliacao_escolhida + ")");
                EditText et = (EditText) rootview.findViewById(R.id.editText);
                i.putExtra(Intent.EXTRA_TEXT, "AVALIAO:" + avaliacao_escolhida + "\n" + "MOTIVO:" + "\n"
                        + et.getText().toString());
                try {
                    startActivity(Intent.createChooser(i, "Send mail..."));
                } catch (android.content.ActivityNotFoundException ex) {
                    Log.d("Deu", "RUim");
                }
            }
        }
    });

    return rootview;
}

From source file:com.salesforce.marketingcloud.android.demoapp.ui.CloudPageInboxActivity.java

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

    if (getSupportActionBar() != null) {
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setTitle(getResources().getString(R.string.app_name));
    }/* w  ww.  j  a  v a2s .  c  o  m*/

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    RadioGroup filterRadioGroup;
    final ListView cloudPageListView;

    filterRadioGroup = findViewById(R.id.filterRadioGroup);
    cloudPageListView = findViewById(R.id.cloudPageListView);

    filterRadioGroup.setOnCheckedChangeListener(radioChangedListener);

    cloudPageListView.setOnItemClickListener(cloudPageItemClickListener);
    cloudPageListView.setOnItemLongClickListener(cloudPageItemDeleteListener);

    MarketingCloudSdk.requestSdk(new MarketingCloudSdk.WhenReadyListener() {
        @Override
        public void ready(@NonNull MarketingCloudSdk marketingCloudSdk) {
            marketingCloudSdk.getAnalyticsManager().trackPageView("data://CloudPageInbox",
                    "Cloud Page Inbox index view displayed", null, null);
            cloudPageListAdapter = new MyCloudPageListAdapter(marketingCloudSdk);
            cloudPageListView.setAdapter(cloudPageListAdapter);
        }
    });

}

From source file:fr.eoit.activity.fragment.iteminfo.PricesFragment.java

@Override
public void onLoadFinished(Cursor cursor) {

    if (DbUtil.hasAtLeastOneRow(cursor)) {

        int chosenPriceId = cursor.getInt(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_CHOSEN_PRICE_ID));

        pricesInfos = new Bundle();

        double buyPrice = PricesUtils.getPriceOrNaN(cursor, Prices.COLUMN_NAME_BUY_PRICE);
        double sellPrice = PricesUtils.getPriceOrNaN(cursor, Prices.COLUMN_NAME_SELL_PRICE);
        double producePrice = PricesUtils.getPriceOrNaN(cursor, Prices.COLUMN_NAME_PRODUCE_PRICE);
        double fixedPrice = PricesUtils.getPriceOrNaN(cursor, Prices.COLUMN_NAME_OWN_PRICE);

        long lastUpdate = cursor.getLong(cursor.getColumnIndexOrThrow(Prices.COLUMN_NAME_LAST_UPDATE));

        pricesInfos.putDouble("buyPrice", buyPrice);
        pricesInfos.putDouble("sellPrice", sellPrice);
        pricesInfos.putDouble("producePrice", producePrice);
        pricesInfos.putInt("chosenPriceId", chosenPriceId);

        RadioButton bTv = ((RadioButton) getView().findViewById(R.id.buy_price));
        RadioButton sTv = ((RadioButton) getView().findViewById(R.id.sell_price));
        RadioButton pTv = ((RadioButton) getView().findViewById(R.id.produce_price));
        RadioButton fTv = ((RadioButton) getView().findViewById(R.id.fixed_price));
        TextView prTv = ((TextView) getView().findViewById(R.id.profit));
        prTv.setVisibility(View.VISIBLE);

        PricesUtils.setPrice(bTv, buyPrice, true);
        PricesUtils.setPrice(sTv, sellPrice, true);
        PricesUtils.setPrice(pTv, producePrice, true);
        PricesUtils.setPrice(fTv, fixedPrice, true);

        if (!Double.isNaN(fixedPrice) && fixedPrice != 0 && chosenPriceId != EOITConst.SELL_PRICE_ID
                && chosenPriceId != EOITConst.BUY_PRICE_ID) {
            ViewUtil.hide(bTv, sTv);/*from   w ww  . jav  a 2 s .  co  m*/
            ViewUtil.show(fTv);
        } else {
            ViewUtil.show(bTv, sTv);
            ViewUtil.hide(fTv);
        }

        if (Double.isNaN(buyPrice) && Double.isNaN(sellPrice)) {
            ViewUtil.show(fTv);
        }

        double profit = 0;
        if (!Double.isNaN(fixedPrice) && fixedPrice != 0 && producePrice > 0 && !Double.isNaN(producePrice)) {
            profit = (fixedPrice - producePrice) / producePrice;
        } else if (sellPrice > 0 && !Double.isNaN(sellPrice) && producePrice > 0
                && !Double.isNaN(producePrice)) {
            profit = (sellPrice - producePrice) / producePrice;
        } else {
            prTv.setVisibility(View.GONE);
        }
        prTv.setText(nfPercent.format(profit));
        pricesInfos.putDouble("profit", profit);

        if (producePrice < 0.01 || Double.isNaN(producePrice)) {
            pTv.setVisibility(View.GONE);
        } else {
            pTv.setVisibility(View.VISIBLE);
        }

        switch (chosenPriceId) {
        case EOITConst.BUY_PRICE_ID:
            bTv.setBackgroundResource(R.drawable.bg_price_selected);
            sTv.setBackgroundResource(R.drawable.bg_selector);
            pTv.setBackgroundResource(R.drawable.bg_selector);
            fTv.setBackgroundResource(R.drawable.bg_selector);
            break;

        case EOITConst.SELL_PRICE_ID:
            sTv.setBackgroundResource(R.drawable.bg_price_selected);
            bTv.setBackgroundResource(R.drawable.bg_selector);
            pTv.setBackgroundResource(R.drawable.bg_selector);
            fTv.setBackgroundResource(R.drawable.bg_selector);
            break;

        case EOITConst.PRODUCE_PRICE_ID:
            pTv.setBackgroundResource(R.drawable.bg_price_selected);
            bTv.setBackgroundResource(R.drawable.bg_selector);
            sTv.setBackgroundResource(R.drawable.bg_selector);
            fTv.setBackgroundResource(R.drawable.bg_selector);
            break;

        case EOITConst.OWN_PRICE_ID:
            pTv.setBackgroundResource(R.drawable.bg_selector);
            bTv.setBackgroundResource(R.drawable.bg_selector);
            sTv.setBackgroundResource(R.drawable.bg_selector);
            fTv.setBackgroundResource(R.drawable.bg_price_selected);
            break;

        default:
            break;
        }

        RadioGroup priceRadioGroup = (RadioGroup) getView().findViewById(R.id.PRICE_RADIO_GROUP);
        priceRadioGroup.setOnCheckedChangeListener(new PriceRadiogroupOnCheckedChangeListener(itemId));

        PricesDialogOnLongClickListener listener = new PricesDialogOnLongClickListener(itemId,
                getFragmentManager());
        bTv.setOnLongClickListener(listener);
        sTv.setOnLongClickListener(listener);
        pTv.setOnLongClickListener(listener);
        fTv.setOnLongClickListener(listener);

        // if price was updated more than 6h ago launch a full update
        if ((new Date().getTime() - lastUpdate) > (6 * 60 * 60 * 1000)) {
            // Update prices
            Parameters.validateStationParams(getActivity().getApplicationContext());
            PriceUpdaterService.launchDeepFullPriceUpdateForItemId(itemId,
                    getActivity().getApplicationContext());
        }
    }
}

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

/**
 * Updates current RSVP display//from  ww  w . ja  v  a  2  s.c o m
 * @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.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  ww .j ava2 s . com
        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();
        }
    });
}