我在那里找到了很多简单的 AlertDialog 示例,但是我遇到的教程和信息似乎与我需要做的事情来帮助我解决我的问题不够接近。我难住了。
我正在开发一个地图应用程序,在用户的搜索结果返回后,我得到了他们查询的 3 个最接近结果的列表。结果存储在“目标”对象的数组中,现在我想将这个对象数组传递给一个对话框,让用户单击他们想要导航到的目的地。每个 Targets 对象都有(作为实例变量)索引、纬度、经度、名称、地址和与当前位置的距离。此时,可点击列表中我真正想要的只是到该位置的距离(四舍五入到百分之一英里):
Math.round(target[i].getDistance()*100.0))/100.0 + " Miles to Destination"
(也许必须把它做成一个字符串,我不知道。)
和目的地名称:
target[i].getName()
理想情况下,我希望将这两个字段打印在对齐良好的列中。我想我需要通过在列表布局中设置宽度来做到这一点?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/distance"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp" >
</TextView>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp" >
</TextView>
</LinearLayout>
好的,这就是我所得到的。如何构建一个接受我的 Targets[] 并为用户显示选择的对话框?(抱歉,我没有任何代码可以作为我对话的起点。我尝试过的任何方法都不起作用,因此将其粘贴在这里似乎不值得。)
谢谢!