Dialog和Asynctaks的行为

时间:2015-02-17 10:54:24

标签: android android-asynctask ftp android-alertdialog

我怀疑我正在做的带有对话的Asynctask的行为。基本上我在我的偏好中有一个字段。如果它是真的我必须显示一个带有3个字段的Dialog填充它们,之后我将此信息附加到我拥有的文件中并通过FTP发送。如果它是假的我用FTP直接发送我的文件。

public void altaAction(View view){

    if(checkFields()){
        if(prefs.getBoolean("myOption", false))
            createPartidaDialog();
        //Here I prepare my file with some info
        altArtFile.add(...);
        ...
        ...
        ...

       //If my option is false I send my file
        if(!prefs.getBoolean("myOption",false))
            new AsyncSender().execute(altaArtFile);
}


private void createPartidaDialog() {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(AltaArtActivity.this);
    alertDialog.setTitle("Partida");
    alertDialog.setMessage("Inserta Datos Partida");

    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);

    final EditText cajasInput = new EditText(this);
    cajasInput.setHint("Cajas");
    cajasInput.setSingleLine(true);
    cajasInput.setImeOptions(EditorInfo.IME_ACTION_NEXT);
    cajasInput.setInputType(InputType.TYPE_CLASS_NUMBER);
    layout.addView(cajasInput);

    final EditText kilosInput = new EditText(this);
    kilosInput.setHint("Kilos");
    kilosInput.setSingleLine(true);
    kilosInput.setImeOptions(EditorInfo.IME_ACTION_NEXT);
    kilosInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);

    layout.addView(kilosInput);

    final EditText precioInput = new EditText(this);
    precioInput.setHint("Precio");
    precioInput.setSingleLine(true);
    precioInput.setImeOptions(EditorInfo.IME_ACTION_DONE);
    precioInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    layout.addView(precioInput);
    alertDialog.setView(layout);

    alertDialog.setPositiveButton("Aceptar",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    try{
                        //Append the info to existing file
                        altaArtFile.add(info);
                        altaArtFile.add(info);
                        altaArtFile.add(info);

                        //Send my file with AsyncSender
                        new AsyncSender().execute(altaArtFile);
                        dialog.dismiss();
                        AltaArtActivity.this.finish();
                    }catch(SQLException e){
                        e.printStackTrace();
                    }
                }
            });

    alertDialog.setNegativeButton("Cancelar",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });

    alertDialog.show();

我遇到的问题是我的FTP服务器两次获取我的文件,例如,如果我两次调用Asyncsender,我不知道为什么会这样。也许这不是一个设计良好的解决方案。任何帮助都会非常感激。非常感谢你

0 个答案:

没有答案