您好,下面的代码似乎无法正常工作,是我做错了什么吗?
基本上发生的情况是我收到字符串 prd|50126057|12bars|5
并且我尝试将其拆分为三个不同的 textView;当我运行它时,它只在第一个 textView 中显示 prd,而其他 TextView 不会改变。为什么会出现这种情况?
我可以看到它在日志中工作,只是没有在其他 TextView 中显示它。
非常感谢任何帮助,并提前致谢。
另外,我很抱歉,如果这个问题已经得到解答,我确实在这里做了一些搜索,但找不到任何东西。
public void messageReceived(String message) {
String response = message;
String[] words = response.split("\\|");
TextView tv1 = (TextView) findViewById(R.id.textView1);
TextView tv2 = (TextView) findViewById(R.id.textView2);
TextView tv3 = (TextView) findViewById(R.id.textView3);
tv1.setText(words[0]);
tv2.setText(words[1]);
tv3.setText(words[2]);
Log.e("items-->", "" + words[0] + " " + words[1] + " " + words[2]+ " " + words[3]);
publishProgress(message);
}
最佳答案
String[] words;
String s="prd|50126057|12bars|5";
words= s.split("\\|");
for(int i=0;i<words.length;i++)
{
System.out.println("Shifted: " +words[i]);
}
关于java - Android .split 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15947311/