如何显示在文本视图Android的键入文本 [英] How to display typed text in text view Android

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

问题描述

我无法显示在文本视图中的文本。我想打一个聊天/短信风格的应用程序。此外,如何将我有一个边框我的文字显示字段,以便它看起来不错。谢谢!我为我的烦恼AHED时间表示歉意。

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=横向>
     <的TextView
        机器人:ID =@ + ID / textView1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =400dp
        机器人:文本=/>
    < EditText上机器人:ID =@ + ID / edit_message
        机器人:layout_weight =1
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:提示=@字符串/ edit_message
        机器人:layout_gravity =底部/>

    <按钮
        机器人:ID =@ + ID / button_send
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:的onClick =的sendMessage
        机器人:文本=@字符串/ button_send
        机器人:layout_gravity =底部/>
 

 公共类MainActivity延伸活动{

    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
    }



  @覆盖
    公共布尔onCreateOptionsMenu(功能菜单){
        //充气菜单;这增加了项目操作栏,如果它是present。
        。getMenuInflater()膨胀(R.menu.main,菜单);
        返回true;
    }

  Button按钮=(按钮)findViewById(R.id.button_send);

    };
 

解决方案

这为西港岛线的工作肯定

 公共类MainActivity延伸活动{

@覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
}

公共无效的sendMessage(视图v){

    EditText上editMessage =(EditText上)findViewById(R.id.edit_message);
    TextView中的TextView =(TextView中)findViewById(R.id.textView1);

    //从得到的EditText文本,并将其转换为字符串
    。字符串messageString = editMessage.getText()的toString();

    //从EditText上设置字符串的TextView
    textView.setText(messageString);

    //明确的EditText发送文本消息后,
    editMessage.setText();


}

}
 

I am having trouble displaying the text in a text view. I want to make a chat/texting style app. Also, how would I have a border around my text View field so that it looks nice. Thank You! and I apologize for my troubles ahed of time.

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
     <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="400dp"
        android:text="" />
    <EditText android:id="@+id/edit_message"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:hint="@string/edit_message" 
        android:layout_gravity="bottom" />

    <Button
        android:id="@+id/button_send"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="sendMessage"
        android:text="@string/button_send" 
        android:layout_gravity="bottom"/>

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }



  @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

  Button button = (Button)findViewById(R.id.button_send);

    };

解决方案

This wil work for sure

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

public void sendMessage(View v){

    EditText editMessage=(EditText)findViewById(R.id.edit_message);
    TextView textView = (TextView) findViewById(R.id.textView1);

    //get text from edittext and convert it to string
    String messageString=editMessage.getText().toString();

    //set string from edittext to textview
    textView.setText(messageString);

    //clear edittext after sending text to message
    editMessage.setText("");


}

}

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

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