1. Download our Official Android App: Forums for Android!

Apps problems with displaying my alert dialog

Discussion in 'Android Development' started by iust79, Aug 2, 2011.

  1. iust79

    iust79 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Aug 2, 2011

    Aug 2, 2011
    1
    0
    5
    Hi!
    I am newbie on android and I need some help with displaying a prompt user input.

    first of all, when I make a Toast display the view with my buttons dissapear and after the Toast close they don't reapear.
    secondly I would like to use that AlertDialog form to get user input, process the text and then permit user to input again another phrase. How can I display again the prompt input user form (that I creat at onCreate event)?

    Here is my code so far:

    import android.os.Bundle;
    import android.text.Editable;
    import java.util.Collections;
    import java.util.Arrays;
    import java.util.ArrayList;

    import android.view.View;
    import android.widget.TextView;
    import android.widget.EditText;
    import android.widget.Toast;
    import android.app.AlertDialog;
    import android.content.DialogInterface;

    public class ShufflephraseActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle("Shuffle phrase");
    alert.setMessage("Input your phrase and then click OK");

    final EditText input = new EditText(this);
    alert.setView(input);
    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
    String value1 = input.getText().toString();
    if (value1.length() == 0) {

    Toast.makeText(getApplicationContext(), "Please enter a text!",
    Toast.LENGTH_SHORT).show();
    return;
    }
    else {
    Toast.makeText(getApplicationContext(), "Processing!",
    Toast.LENGTH_SHORT).show();
    dialog.dismiss();
    }

    }
    }
    );

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton)
    {
    dialog.dismiss();
    }
    });

    alert.show();

    }

    }
     

    Attached Files:


    Advertisement

Share This Page

Loading...