我發現了很多簡單的AlertDialog示例,但我遇到的教程和信息似乎並沒有足夠接近我需要做的來幫助我解決問題。我很難過。Android:將對象傳遞給CustomDialog?
我正在製作地圖應用程序,並且在用戶的搜索結果返回後,我已經列出了他們查詢的3個最接近的結果。結果存儲在一個「目標」對象數組中,現在我想將這個對象數組傳遞給一個對話框,讓用戶點擊他們想要導航到的目的地。每個目標對象都有(作爲實例變量)一個索引,一個緯度,一個經度,一個名稱,一個地址和距離當前位置的距離。在這一點上,我真正想要的點擊列表是位置(四捨五入到一英里的百分之)距離:
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>
好的,這就是我已經得到的。我如何構建一個接受我的目標[]並顯示用戶選擇的對話框? (對不起,我沒有任何的代碼給你看作爲一個起點,我的對話,沒有什麼我已經試過的作品在所有所以它似乎並不值得粘貼到此處。)
謝謝!
也許是一個'Parcelable'目標對象? – PearsonArtPhoto 2012-03-22 14:51:05
我從來沒有得到這個工作,我想要的方式。編程有點高於我的頭。沒關係,但是,我以不同的方向應用了該應用,結果可以接受。 – pjd 2012-05-05 20:56:38