Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Pass an Object into a CustomDialog?
    text
    copied!<p>I've found plenty of simple AlertDialog examples out there, but the tutorials and information I've come across doesn't seem to come close enough to what I need to do to help me solve my problem. I'm stumped.</p> <p>I'm working on a mapping app, and after the user's search results come back I've got a list of the 3 closest results for their query. The results are stored in an array of "Targets" objects, and now I want to pass this array of objects to a dialog box that will let the user click the destination they want to navigate to. Each Targets object has (as instance variables) an index, a latitude, a longitude, a name, an address, and a distance from the current location. At this point, all I really want in the clickable list are distance to the location (rounded to hundredths of a mile): </p> <pre><code>Math.round(target[i].getDistance()*100.0))/100.0 + " Miles to Destination" </code></pre> <p>(maybe that has to be made into one String, I don't know.)</p> <p>and the name of the destination:</p> <pre><code>target[i].getName() </code></pre> <p>Ideally, I'd like these two fields to be printed in nicely aligned columns. I think I need to do this by setting widths in my list layout?</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" &gt; &lt;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" &gt; &lt;/TextView&gt; &lt;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" &gt; &lt;/TextView&gt; &lt;/LinearLayout&gt; </code></pre> <p>OK, that's as far as I've gotten. How do I construct a dialog that will accept my Targets[] and display choices for a user? (Sorry I don't have any code to show you as a starting point for my dialog. Nothing I've tried works at all so it didn't seem worth it to paste it here.)</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload