単純な AlertDialog の例はたくさんありますが、私が見つけたチュートリアルや情報は、私が問題を解決するために必要なことに十分に近づいていないようです。私は困惑しています。
私はマッピング アプリに取り組んでおり、ユーザーの検索結果が戻ってきた後、クエリに最も近い 3 つの結果のリストを取得しています。結果は「Targets」オブジェクトの配列に格納されます。このオブジェクトの配列をダイアログ ボックスに渡し、ユーザーが移動先をクリックできるようにします。各 Targets オブジェクトには、(インスタンス変数として) インデックス、緯度、経度、名前、住所、および現在の場所からの距離があります。この時点で、クリック可能なリストに本当に必要なのは、その場所までの距離 (100 分の 1 マイルに四捨五入) だけです。
Math.round(target[i].getDistance()*100.0))/100.0 + " Miles to Destination"
(たぶん、それを1つの文字列にする必要がありますが、わかりません。)
宛先の名前:
target[i].getName()
理想的には、これら 2 つのフィールドを適切に整列した列に印刷したいと考えています。リストのレイアウトに幅を設定してこれを行う必要があると思いますか?
<?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>
OK、それは私が得た限りです。Targets[] を受け入れ、ユーザーの選択肢を表示するダイアログを作成するにはどうすればよいですか? (申し訳ありませんが、ダイアログの開始点として表示するコードがありません。私が試したものはまったく機能しないため、ここに貼り付ける価値はないようです。)
ありがとう!