gpt4 book ai didi

java - 如何解决TextView使用append方法无法添加新文本值的问题

转载 作者:行者123 更新时间:2023-12-01 17:55:20 24 4
gpt4 key购买 nike

value = et1.getText().toString();
budget = Integer.parseInt(value);
description = et2.getText().toString();
et1.getText().clear();
et2.getText().clear();

SharedPreferences pref = getSharedPreferences("prefs", 0)
SharedPreferences.Editor edit = pref.edit();
edit.putInt("Budget”, budget);
edit.putString("Description", description):
edit.commit();

MainClass
TextView budgettv;

budgettv = (TextView)findViewById(R.id.budgettv);
budgettv.append(budget + " Description: " + description + "\n");

xml
<TextView
android:id="@+id/budgettv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceMedium" />

我正在使用 editText 输入值并在预算电视中显示输入的值。我想在下一行添加新文本,但是当我使用追加时,它会覆盖旧值。如何在不替换旧值的情况下添加新值。

最佳答案

您可以使用 StringBuilder 来附加数据,如下所示

    StringBuilder sb =new StringBuilder(budget);
sb.append(" Description: " + description );
sb.append(System.getProperty(System.lineSeparator()));//Hear for new line
budgettv.setText(sb);

关于java - 如何解决TextView使用append方法无法添加新文本值的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60727504/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com