简体   繁体   English

单击Android Studio中的按钮后,如何在TextView中显示输入的文本?

[英]How to display inputted text in a TextView after clicking a button in Android studio?

So I am experimenting with Android Studio. 因此,我正在尝试使用Android Studio。 I am stuck in the part where I want my "Submit" button to display the user inputted text underneath the page. 我被困在希望“提交”按钮在页面下方显示用户输入的文本的部分。

Button submit is the button. 按钮提交就是按钮。 "name" and "email" are the EditText variables aka text fields My TextView variable is outputText “名称”和“电子邮件”是EditText变量,又名文本字段,我的TextView变量是outputText

So after the user enters random stuff in both text fields and click submit, I want my outputText to display both texts that were inputted in 2 separate lines 因此,在用户在两个文本字段中输入随机内容并单击提交之后,我希望我的outputText显示在2行中输入的两个文本

ex: 例如:

John Smith 约翰·史密斯

john.smith@gmail.com john.smith@gmail.com

The code below is my .java code for the activity. 下面的代码是我的活动的.java代码。 I need to know how to initialize the new intent in a way that lets me do the 4 lines below it. 我需要知道如何以一种使我能够执行下面的4行的方式来初始化新的意图。 Thanks. 谢谢。

public void buttonOnClick(View v){
    Button submit = (Button) v;

    submit.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent i =
                    new Intent(...?...);
            startActivity(i);
        }
    });
    editName = (EditText) findViewById(R.id.name);
    editEmail = (EditText) findViewById(R.id.email);

    textout = (TextView) findViewById(R.id.textView);
    textout.setText(editName.getText()+" "+editEmail.getText());


}    

I want my outputText to display both texts that were inputted in 2 separate lines 我希望我的outputText显示在2行中输入的两个文本

Use <br> and Html.fromHtml between text to add new line: 在文本之间使用<br>Html.fromHtml添加新行:

String strText=(String)editName.getText()+"<br>"+(String)editEmail.getText();
textout.setText(Html.fromHtml(strText));

how to initialize the new intent in a way that lets me do the 4 lines below it... 如何以一种新的方式初始化新的意图,让我在其下方执行4行...

Intent i =new Intent(CurrentActivityName.this,TargetActivityName.class);
startActivity(i);

For print in next line 用于下一行打印

textout.setText(editName.getText()+"\n"+editEmail.getText());

For intent 为了意图

Intent i =new Intent(FirstActivity.this,SecondActivity.class);
startActivity(i);

Ok I was able to accomplish what I wanted without an Intent initialized. 好的,无需初始化Intent就可以完成我想要的事情。 Here's the code: 这是代码:

    public void buttonOnClick(){
    Button submit = (Button) findViewById(R.id.submit);
    editName = (EditText) findViewById(R.id.name);
    editEmail = (EditText) findViewById(R.id.email);
    textout = (TextView) findViewById(R.id.outputText);

    submit.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
             textout.setText(editName.getText()+"\n"+editEmail.getText());
        }
    });


}    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击“提交”按钮后如何显示输入的数据? - How to display my inputted data after clicking “submit” button? 单击按钮后如何更新 TextView 文本 - How to update TextView text after clicking a button 在Android中按下Button后,如何在textView的RadioButton中显示文本? - How to display the text in Radiobutton in the textView after Button is pressed in Android? Android Studio - 如果按下按钮且文本框中没有文本,则显示一个字符串,输入文本时显示另一个字符串 - Android Studio- Display one string if a button is pressed with no text in the textbox and another when text is inputted 在Android Studio中单击“提交”按钮后,如何将输入的值存储到变量并在屏幕上显示它们? - How to store entered values to variables and display them on screen after clicking submit button in Android Studio? 如何在 function 中使用 textview Android Studio 在 Z93F725A074233FEC889ZDF48 中显示文本 - How can I display text in a function with textview Android Studio in java Android如何通过单击按钮更改Textview的数据 - Android How to change data of Textview by clicking on button 在Android Studio中输出输入的文本 - Outputting inputted text in Android Studio Android Studio 按钮清除 TextView 文本 - Android Studio Button to clear TextView text 单击按钮后如何下载文件(Android Studio) - How to download a file after clicking a button (Android Studio)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM