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