Comment puis-je configurer un espace réservé sur Edittext dans Android et de l'utiliser si aucune entrée n'a été tapé par l'utilisateur?

Je voudrais avoir un EditText dans android où j'ai un espace réservé, qui sera utilisée COMME mon entrée si l'utilisateur tape rien. L'édition de texte est utilisé dans une invite dans mon cas.

Je suis conscient de "soupçon" excisting, qui est un espace réservé, mais elle ne l'utilise pas comme une entrée. Si j'ai de l'indice défini à "AAA" et que l'utilisateur tape rien et appuie sur "OK" je vais avoir une chaîne vide, pas de "AAA".

Voici mon code:

private void promptForUsername(){
        //get prompts.xml view
        LayoutInflater layoutInflater = LayoutInflater.from(context);

        View promptView = layoutInflater.inflate(R.layout.prompts, null);

        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);

        //set prompts.xml to be the layout file of the alertdialog builder
        alertDialogBuilder.setView(promptView);

        final EditText input = (EditText) promptView.findViewById(R.id.userInput);


        //setup a dialog window
        alertDialogBuilder
        .setCancelable(false)
        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                //get user input and set it to result
                addEvent(levelSelected, input.getText().toString(), Integer.parseInt(points), time + "s");
                sqlLogic();
            }
        })
        .setNegativeButton("Cancel",
                new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                sqlLogic();
                dialog.cancel();
            }

        });
        //create an alert dialog
        AlertDialog alertD = alertDialogBuilder.create();
        alertD.show();

        input.setFocusableInTouchMode(true);
        input.requestFocusFromTouch();

        InputMethodManager lManager = (InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE); 
        lManager.showSoftInput(input, 0);

    }
version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="10dp" >

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Type username:"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/userInput"
        android:layout_width="match_parent"
        android:inputType="text"
        android:layout_height="wrap_content"
        android:maxLength="13" 
        android:hint="AAA">

        <requestFocus />
    </EditText>
</LinearLayout>
Je trouve la réponse dans stackoverflow.com/questions/8221072/... dans le xml, ajouter: android:hint="texte"

OriginalL'auteur Vanquiza | 2014-05-16