我试过这段代码,但它只显示最后一个字:
signButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String speech = "This code is sample";
String[] result = speech.split("\\s");
for (int x=0; x<result.length; x++) {
textView.setText(result[x]);
}
}
});
好的,首先我花了一些时间才理解您的问题,我仍然不确定,据我所知,您想在单击按钮时显示在 textView 中添加的下一个 WORD。. .
为此,您可以使用以下代码。
//String Array preparation
String speech = "This code is sample";
String[] result = speech.split("\\s");
int count = 0;
signButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//check if array has more values to add or whatever you want to check
if(count<result.length){
if(count==0){
textView.append(result[count];
} else {
textView.append(" " + result[count];
}
count++;
}
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句