Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 字符串数组:显示结果_Java_Android_Arrays_Google Places Api - Fatal编程技术网

Java 字符串数组:显示结果

Java 字符串数组:显示结果,java,android,arrays,google-places-api,Java,Android,Arrays,Google Places Api,我想我可以接受从两个AutoCompleteTextView获取的用户输入,并将其显示为一个TableLayout的结果 AutoCompleteTextView接受的两个输入是来自用户的My Location和Destination。复杂性来自于AutoCompleteTextView生成的输入类型。AutoCompleteTextView使用谷歌的placesautomplete,因此我正在使用类似尼泊尔中部地区贾马尔(Jamal)、加德满都(Kathmandu)以及尼泊尔中部地区卡兰基(K

我想我可以接受从两个
AutoCompleteTextView
获取的用户输入,并将其显示为一个
TableLayout
的结果

AutoCompleteTextView
接受的两个输入是来自用户的My LocationDestination。复杂性来自于
AutoCompleteTextView
生成的输入类型。
AutoCompleteTextView
使用谷歌的
placesautomplete
,因此我正在使用类似尼泊尔中部地区贾马尔(Jamal)、加德满都(Kathmandu)以及尼泊尔中部地区卡兰基(Kalanki)、加德满都(Kathmandu)的输入。我希望
TableLayout
反映的是结果:来自。。。到…

我的问题是如何在尼泊尔中部地区加德满都的贾马尔(Jamal)输入字符串的第一部分,即贾马尔(Jamal),以便
表格布局
显示结果,如结果:从贾马尔到卡兰基。作为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 =  location.getString().toText();
将它们分配给
字符串
,然后执行此操作

results.setText(new StringBuilder().append("Results from"+from).append(" to"+to));
这样做:

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 =  location.getString().toText();

results.setText(new StringBuilder().append("Results from"+from).append(" to"+to));

我想我找到了以我想要的方式显示结果的答案

我不确定这些数组声明的作用,但它们不会编译。它确实有效,但我得到了地址的完整部分。比如,如果输入是尼泊尔中部地区加德满都卡兰基
Kalanki
,我只想在结果显示中获得
Kalanki
。。。用代码。。。我得到了完整的地址我正在使用字符串数组,这样我就可以修改用户输入。。。比如,如果他们要输入一个地址,比如尼泊尔中部地区加德满都卡兰基
,或者可能是加德满都卡兰基
,我只想让他们看到第一个单词,在本例中是
卡兰基
但是location.getString().toText();返回字符串,而不是字符串数组。您可以创建一个新的字符串,并根据需要进行修改,然后将其显示给用户。hmmm。。。我不明白你。。。很抱歉如果你能给我举个例子??
String from =  location.getString().toText();

results.setText(new StringBuilder().append("Results from"+from).append(" to"+to));
    String from_split = location.getText().toString();
    String to_split = destination.getText().toString();
    if(from_split.contains(","))
    {
        from = from_split.split(",");
    }
    else
    {
        from = from_split.split(" ");
    }
    if(to_split.contains(","))
    {
        to = to_split.split(",");
    }
    else
    {
        to = to_split.split(" ");
    }
    results.setText(new StringBuffer().append(from[0]).append(" to "+to[0]));