java - 字符串数组: Displaying Results

标签 java android arrays google-places-api

我想我可以接受从两个 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/

相关文章:

java - 未经检查或不安全的操作错误

java - 从 JSON 字符串确定时区?

java - 修复了文本字段上的日期分隔符 (dd-mm-YYYY)

java - 比较数组java

javascript - 如何使用 Javascript 将数组的值转换为每个条目中的不同键?

java - 从 Java 中的字符串数组中删除未填充的值或空值

java - Android 图像旋转在 Ice Cream Sandwich 中不起作用

android - 你好 ListView 教程问题

android - 谷歌云端点错误 : Process exited before success message

javascript - 如何获取对象数组中某些特定属性的重复值的计数并将其存储在对象中