Android:单击按钮时将新文本行添加到 edittext

发布于 2025-01-07 07:49:15 字数 255 浏览 2 评论 0原文

我是 Android 新手:) 我想做的是每当按下按钮时向 edittext 添加新的文本行。 例如: 您输入一个数字 (2) 按下按钮 EditText 显示“您已按 2” 当您重复使用新号码时 (3) 编辑文本将显示.. “您已输入3” “您已输入 2”

我希望它记录在编辑文本中输入的数字。

我已经完成了所有设置,当输入按钮时它会在 edittext 中显示该行,我只是不知道如何保留上一行文本,将其移动到第二行并将新行放在顶部。

谢谢你!!

I am new to Android :)
What I am trying to do is add a new line of text to edittext whenever the button is pressed.
For example:
you enter in a number (2)
Press the button
EditText displays "you have pressed 2"
when you repeat with a new number (3)
Edit Text will display..
"you have entered 3"
"you have entered 2"

I want it to make a log of the numbers entered in edittext.

I have everything set up already where it displays the line in edittext when the button is entered, I just dont know how to keep the previous line of text, move it to the 2nd line and have the new line on the top.

Thank you!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇女薄笑 2025-01-14 07:49:15

我不确定它是否有效

public void onClick(View v) {
       TextView tx = (TextView) findViewById(R.id.text_box);
       StringBuilder builder = new StringBuilder();

       for (String s : words){
         builder.append(s+" ");
         tx.setText(builder.toString());
       }

I am not sure bt it might work

public void onClick(View v) {
       TextView tx = (TextView) findViewById(R.id.text_box);
       StringBuilder builder = new StringBuilder();

       for (String s : words){
         builder.append(s+" ");
         tx.setText(builder.toString());
       }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文