Comment faire pour effacer le texte dans TextView Android?

Donc j'ai un Android programme comme suit:

package com.example.androiddemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class AndroidDemo extends Activity {
    String[] messages = {"Short Text",
                         "I want to show some really long text" +
                         "on the display of the phone. " +
                         "Having run out of ideas on what to type, " +
                         "I am adding this text which makes absolutely " +
                         "no sense."};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final Button add = (Button) findViewById(R.id.addBtn);
        final Button clear = (Button) findViewById(R.id.clrBtn);
        final EditText text = (EditText) findViewById(R.id.display);

        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(v == add){
                    text.setText(messages[new java.util.Random().nextInt(messages.length)]);
                }else if(v == clear){
                    text.setText("");
                }
            }
        });
    }
}  

Le bouton pour ajouter du texte à la TextView fonctionne parfaitement bien mais le texte ne jamais s'efface.

Ma conviction est que l'opération de TextView serait analogue à JTextField ou JTextArea où le paramètre le texte à "" efface.

Comment faire pour effacer le texte?

Essayez de ne pas mélanger jusqu' TextView et EditText. Un EditText est analogue à JTextField/JTextArea, et TextView avec JLabel (et l'équivalent de la plus grande non-modifiable par l'utilisateur de la boîte)
Merci pour la mention !! 🙂

OriginalL'auteur Little Child | 2013-07-04