在不替换Sketchware的情况下设置TextView文本

huangapple go评论92阅读模式
英文:

setText on textview without replacing sketchware

问题

我需要在不替换所有文本的情况下编辑文本视图,例如
myText:Hi
如果我点击按钮,它将添加“Hello”,因此它应该是这样的:“Hi Hello”,而不是替换所有文本。

对不起,英语不太好。

我使用了setText,它替换了所有文本。

英文:

I need to edit the textview without replacing the all text, for example
myText : Hi
Like if i click the button it will add "Hello" , so it should be like this "Hi Hello" without replacing the all text.

Sorry for bad English.

I used setText and it replace all text

答案1

得分: 0

尝试这个方法

这是你的第一个文本视图

textview1.setText("你好");

如果你的按钮被点击,添加这段代码将"你好"更改为"你好 你好"

button1.setOnClickListener(new View.OnClickListener(){
	@Override
	public void onClick(View _view){
		textview1.setText(textview1.getText().toString().concat(" 你好"));
	}
});
英文:

try this way

This is your first text view

textview1.setText("hi");

And if your button clicked , add this code for change "hi" to "hi hello"

button1.setOnClickListener(new View.OnClickListener(){
	@Override
	public void onClick(View _view){
		textview1.setText(textview1.getText().toString().concat(" hello"));
	}
});

huangapple
  • 本文由 发表于 2023年3月3日 20:52:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75627320.html
  • sketchware
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定