如何在同一视图中显示在文本框中输入的文本 [英] How to display the text entered in the text box in the same view

查看:145
本文介绍了如何在同一视图中显示在文本框中输入的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在同一视图中显示在文本框中输入的文本



i想要输入文本,然后想要在同一视图中显示它,如twitter 。



我正在使用eclipse juno为Android应用程序编码。



援助将高度可观



谢谢

How to display the text entered in the text box in the same view

i want to enter the text and then want to display it in the same view like twitter.

I am coding using eclipse juno for android app.

Assistance will be high appreciable

Thanks

推荐答案

1。在EditText控件之后的res / layout / activity_my.xml中添加textview控件:

1. Add a textview control in the res/layout/activity_my.xml after the EditText control:
<textview>
        android:id="@+id/text_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="" /></textview>



2.向Button控件添加一个onclick监听器:


2. add an onclick listener to the Button control:

<button>
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="@string/button_send"
  android:onClick="sendMessage" /></button>





3.最后,在MyActivity.java中:

//当用户点击发送按钮



3. Lastly, in the MyActivity.java:
// Called when the user clicks the Send button

public void sendMessage(View view) {

    EditText editText = (EditText) findViewById(R.id.edit_message);
    String message = editText.getText().toString();
    TextView textView = (TextView) findViewById(R.id.text_id);
    textView.setText(message);
}


您可以在edittext下面添加一个空文本视图。当用户单击按钮时,您将从edittext获取文本并将其添加到textview。您可以通过键入
You could add an empty textview below the edittext. When user clicks button you get the text from the edittext and add it to the textview. You can get text from an edittext by typing
edittext.getText().toString();


这篇关于如何在同一视图中显示在文本框中输入的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆