Which method fires when creating an AlertDialog?

Which method fires when creating an AlertDialog ?

As onCreate()for operations, My case: I have a fragment, and in this fragment I have a button using this method setOnClickListener():

btnAddPromotionAw.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            AlertDialog.Builder builder = new AlertDialog.Builder(
                    getActivity());

            LayoutInflater inflater = (LayoutInflater) getActivity()
                    .getSystemService(getActivity().LAYOUT_INFLATER_SERVICE);

            View dialog = inflater.inflate(R.layout.promotion_aware_picker,
                    null);
            builder.setView(dialog);

            final AlertDialog alertDialog = builder.create();
            alertDialog.show();

            alertDialog.getWindow().setLayout(600,400);

          }         
    });

I want to execute the below code only on creating an AlertDialog:

ArrayList<Goods> Goodslist = new ArrayList<Goods>();
                            Goodslist = promotionAwAccess
                                    .getGoodsByIsMerch();

                            LinearLayout ll1 = (LinearLayout) alertDialog
                                    .findViewById(R.id.linearLayoutPAGoods);

                            final RadioButton[] rdb = new RadioButton[Goodslist.size()];
                            RadioGroup rdg = new RadioGroup(getActivity());
                            rdg.setOrientation(RadioGroup.VERTICAL);
                            rdg.setGravity(Gravity.RIGHT);

                            for (int i = 0; i < Goodslist.size(); i++) {

                                rdb[i] = new RadioButton(getActivity());
                                rdg.addView(rdb[i]);
                                rdb[i].setText(Goodslist.get(i)
                                        .getGoodsName());
                                rdb[i].setId(i);
                                rdb[i].setButtonDrawable(android.R.color.transparent);
                                rdb[i].setCompoundDrawablesWithIntrinsicBounds(
                                        0, 0, R.drawable.btn_radio_custom,
                                        0);

                            }
                            ll1.addView(rdg);

Sorry for the incomplete explanation first.

+4
source share
3 answers
AlertDialog.Builder builderSingle = new AlertDialog.Builder(
                    DialogActivity.this);
            builderSingle.setIcon(R.drawable.ic_launcher);
            builderSingle.setTitle("Select One Name:-");
            final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
                    DialogActivity.this,
                    android.R.layout.select_dialog_singlechoice);
            arrayAdapter.add("Hardik");
            arrayAdapter.add("Archit");
            arrayAdapter.add("Jignesh");
            arrayAdapter.add("Umang");
            arrayAdapter.add("Gatti");
            builderSingle.setNegativeButton("cancel",
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });

            builderSingle.setAdapter(arrayAdapter,
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String strName = arrayAdapter.getItem(which);
                            AlertDialog.Builder builderInner = new AlertDialog.Builder(
                                    DialogActivity.this);
                            builderInner.setMessage(strName);
                            builderInner.setTitle("Your Selected Item is");
                            builderInner.setPositiveButton("Ok",
                                    new DialogInterface.OnClickListener() {

                                        @Override
                                        public void onClick(
                                                DialogInterface dialog,
                                                int which) {
                                            dialog.dismiss();
                                        }
                                    });
                            builderInner.show();
                        }
                    });
            builderSingle.show();
0
source

AlertDialog.show() . , AlertDialog.setView(View) show(). , ListView. AlertDialog.setView(LayoutInflater.from(content).inflate(R.layout.your-layout-name, null, false)), .

0

: , DialogFragment, Dialog onCreateDialog() :

@Override
public AlertDialog onCreateDialog(Bundle savedInstanceState) {

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = (LayoutInflater) getActivity()
                .getSystemService(getActivity().LAYOUT_INFLATER_SERVICE);

    dialog = inflater.inflate(R.layout.promotion_aware_picker, null);

    builder.setView(dialog);

    final AlertDialog alertDialog = builder.create();
    alertDialog.getWindow().setLayout(100, 100);

    **myMethode();**

    return alertDialog;
}

myMethod(), .

Fragment DialogFragment show().

myDialogFragment dialog = new myDialogFragment();

dialog.show(getActivity().getFragmentManager(),"dialogTag");

.

0

Source: https://habr.com/ru/post/1583935/


All Articles