0 votes

error calling build.create

introducir la descripciĆ³n de la imagen aquĆ­

I have customized a dialog, but as the AlertDialog.Builder does not have dismiss() I removed the builder and now it does not accept the create call due to a display 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 several attempts I solved it. let's see if it helps :)

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;
}

0voto

jirungaray Points 807

You are working with 2 different objects.

The builder as its name says, its responsibility is to configure the parameters of the dialog and return a new instance using the method build() .

IMPORTANT : build() only generates the dialog, in order to display it you must call the method show() of the dialogue.

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

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X