error when calling build.create

0

I have customized a dialog, but since the AlertDialog.Builder does not have dismiss () I removed the builder and now it does not accept the create call due to a vesrion error.

public AlertDialog DespachoAct() {
    final AlertDialog builder = new AlertDialog.Builder(DespachoDActivity.this).show();
    LayoutInflater inflater = DespachoDActivity.this.getLayoutInflater();
    View v = inflater.inflate(R.layout.update_despacho, null);
    builder.setView(v);
    builder.show();
    cb1 = (CheckBox) v.findViewById(R.id.cb1) ;
    txtsoles = (EditText) v.findViewById(R.id.txtsoles);
    txtobs2 = (EditText) v.findViewById(R.id.txtobs2);
    act = (Button) v.findViewById(R.id.btnactualizar2);
    can = (Button) v.findViewById(R.id.btncancelar);
    act.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    DownloadTask2 up = new DownloadTask2();
                    up.execute();
                    new DownloadTask().execute("");
                    builder.dismiss();
                }
            }
    );
    can.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    builder.dismiss();
                }
            }
    );
    /////////// sale : call requires api level 21 (current min is 19)android.app.Dialog#create return builder.create();
     return builder.create();
}

.........................

after making several attempts I solved it. to see if it's useful:)

public AlertDialog DespachoAct(){
    final AlertDialog builder = new AlertDialog.Builder(DespachoDActivity.this).create();
    LayoutInflater inflater = DespachoDActivity.this.getLayoutInflater();
    View v = inflater.inflate(R.layout.update_despacho, null);
    builder.setView(v);
    builder.show();
    cb1 = (CheckBox) v.findViewById(R.id.cb1) ;
    cb1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean isChecked = cb1.isChecked();
            if(isChecked){
                b="1";
            }
            else
            {
                b="";
            }
        }
    });
    txtsoles = (EditText) v.findViewById(R.id.txtsoles);
    txtobs2 = (EditText) v.findViewById(R.id.txtobs2);
    txtrecibo = (EditText) v.findViewById(R.id.txtrecibo);
    act = (Button) v.findViewById(R.id.btnactualizar2);
    can = (Button) v.findViewById(R.id.btncancelar);
    act.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (b=="1" && txtsoles.getText().toString().length()>0 && txtobs2.getText().toString().length()>0
                            && txtrecibo.getText().toString().length()>0){


                        DownloadTask2 up = new DownloadTask2();
                        up.execute();
                        new DownloadTask().execute("");
                        builder.dismiss();

                    }

                    else{
                        Toast.makeText(context, "Se encontraron datos vacios ",Toast.LENGTH_SHORT).show();
                    }

                }
            }
    );
    can.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    builder.dismiss();
                }
            }
    );
    return builder;
}
    
asked by ICRUZ 13.07.2016 в 19:16
source

1 answer

0

You are working with 2 different objects.

The builder as its name says is responsible for configuring the dialog parameters and returning a new instance using the build() method.

IMPORTANT : build() only generates the dialog, so that it is seen you must call the method show() of the dialog.

The Dialog itself is the object that displays dialog on the screen, which has the methods show() and dismiss() to show and hide respectively.

    
answered by 07.09.2016 в 19:06