我想我可以接受从两个 AutoCompleteTextView
获得的用户输入,并将其显示为有 TableLayout
的结果。
AutoCompleteTextView
接受的两个输入是来自用户的我的位置和目的地。复杂性来自于 AutoCompleteTextView 生成的输入类型。 AutoCompleteTextView
使用 Google 的 PlacesAutoComplete
,因此我正在使用诸如 Jamal、Kathmandu、Central Region、Nepal 之类的输入,也许还有 Kalanki,加德满都,中部地区,尼泊尔。我希望 TableLayout
反射(reflect)的是 结果:从 ... 到 ...
我的问题是如何在 Jamal, Kathmandu, Central Region, Monday 中获取字符串的第一部分,这只是 的 Jamal TableLayout
显示结果,例如结果:从 Jamal 到 Kalanki。作为 Android 新手,我有一个模糊的想法,我尝试的代码如下所示。
String[] from;
String[] to;
//pulling the auto complete text view
from = location.getString().toText();
to = destination.getString().toText();
//referencing the text view inside the table layout
results.setText(new StringBuilder().append("Results from"+from[0]).append(" to"+to[0]));
这段代码显然不起作用,因为它提示我将from
更改为String
。我真的不知道发生了什么事。请帮忙?
最佳答案
这样做:
String[] from = new String[]{location.getString().toText()};
String[] to = new String[]{destination.getString().toText()};
results.setText(new StringBuilder().append("Results from"+from[0]).append(" to"+to[0]));
或者
String from;
String to;
from = location.getString().toText();
to = destination.getString().toText();
results.setText(new StringBuilder().append("Results from"+from).append(" to"+to));
希望有帮助。
关于java - 字符串数组: Displaying Results,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15942249/