我想分开句子。我在AutocompleteTextview
中输入,但我无法获得所需的输出:
例如:
The fox jump over the bridge
欲望输出:
The* fox* jump* over* the* bridge*
这是我的代码:
check.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String sentences = autocompletetxt.getText().toString();
String[] splitwords = sentences.split(" ");
for (String biyak : splitwords)
{
textviewdisplaygrammar.setText(biyak + "*");
}
}
});
答案 0 :(得分:1)
我认为您在for循环中重新分配文本值。试试这样:
String foo = "";
check.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String sentences = autocompletetxt.getText().toString();
String[] splitwords = sentences.split(" ");
for (String biyak : splitwords) {
foo = foo + biyak + "* ";
}
textviewdisplaygrammar.setText(foo);
}
});
答案 1 :(得分:0)
只需一条指令即可:
sentences.replaceAll(" ", "* ") + "*";
没有循环,没有任何东西。很快。