title: Android: Dynamically Populate a SlidingDrawer (or a small list) within the Main Activity
body: <p>I am working on an Android mapping app that allows a user to type a search parameter into an EditText box, and then the closest destinations matching the query are plotted with pins on the MapView.</p>
  
  <p>Clicking on a pin will give info about the location, but I would like to provide more information to the user up front. I thought a SlidingDrawer could populate and open up to show the user the names of the destinations/the distances away.</p>
  
  <p>Having spent a lot of time on this, having done much reading, and having made little progress, I am now asking the community for assistance.</p>
  
  <p>The problem I'm having is that I can't figure out how to populate the contents of the SlidingDrawer within the main activity. I am able to launch a new activity, but that takes my MapView off the screen. I need to be able to see the map as well as the SlidingDrawer. And I can't figure out how to populate the SlidingDrawer without it being set up as an Activity. </p>
  
  <p>(And I should say also that it doesn't necessarily need to be a SlidingDrawer that contains the list of destinations. I could modify my layout to make a small (max 3 items) list and take away some of the map's real estate if that is easier, but I'm not sure how to do that, either.)</p>
  
  <p>Here is the code that calls my SlidingDrawer:</p>
  
  <pre><code>            //call SlidingDrawer
          Intent drawerIntent = new Intent(this, SlidingDrawerFinal.class);
          drawerIntent.putExtra("lat", lat);
          drawerIntent.putExtra("lon", lon);
          int numberOfTargetsForList = numberOfLoops;
          drawerIntent.putExtra("numberOfTargetsForList", numberOfTargetsForList);
          for(int i = 0; i &lt; target.length; i++){
              drawerIntent.putExtra("target" + Integer.toString(i), target[i]);
          }
          this.startActivity(drawerIntent);
  </code></pre>
  
  <p>This is the code in my SlidingDrawer class (extends Activity) that fills the list inside the drawer:</p>
  
  <pre><code>    View inflatedDrawerLayout = getLayoutInflater().inflate(R.layout.drawer_main, null);
      int width = getWindow().getAttributes().width;
      int height = 300;
      LayoutParams params = new LayoutParams(width, height);
      getWindow().addContentView(inflatedDrawerLayout, params);
  
      // add some data
              ArrayList&lt;MyData&gt; myDataList = new ArrayList&lt;MyData&gt;();
              myData = new MyData[numberOfTargets];
  
              for(int i = 0; i &lt; numberOfTargets; i++){
                  String lineTwo = "";
                  if(target[i].getRating().equals("Not Yet Rated")){
                      lineTwo = "      " + target[i].getRating() + "                           " + 
                              Double.toString((Math.round(target[i].getDistance()*100.0))/100.0) + " miles";
                  }
                  else{
                      lineTwo = "     rating: " + target[i].getRating() + "/5 stars                    " + 
                              Double.toString((Math.round(target[i].getDistance()*100.0))/100.0) + " miles";  
                  }
                  String lineOne = (Integer.toString(i + 1) + ": " + target[i].getName() + ", " + target[i].getVicinity()) + "\n" + lineTwo;
                  myData[i] = new MyData(lineOne, i);
                  myDataList.add(myData[i]);
  
              }                
  
              mListView = (ListView) findViewById(R.id.listview_);
  
              mListView.setAdapter(new MyListAdapter(this, R.layout.drawer_row, myDataList)); 
              drawer = (SlidingDrawer) findViewById(R.id.drawer);
              handleButton = (Button) findViewById(R.id.handle);
              drawer.animateOpen();
  
              drawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
  
              public void onDrawerOpened() {
                      handleButton.setBackgroundResource(R.drawable.handle_down_white);
                  }
              });
  </code></pre>
  
  <p>My layout files:</p>
  
  <p>main.xml:</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="vertical" &gt;
  
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="10dip"&gt;
          &lt;EditText
              android:id="@+id/geocode_input"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:hint="@string/placeName"
              android:inputType="text"
              android:lines="1" /&gt;    
          &lt;Button 
              android:id="@+id/geocode_button"
              android:layout_width="0dip"
              android:layout_height="wrap_content"
              android:layout_weight="1" 
              android:text="@string/goLabel" /&gt;
      &lt;/LinearLayout&gt;
      &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent" &gt;           
      &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical" &gt;
          &lt;view android:id="@+id/mv"
              class="com.google.android.maps.MapView"
              android:layout_width="fill_parent"
              android:layout_height="0dip"
              android:layout_weight="1" 
              android:clickable="true"
              android:apiKey="my_API_Key"/&gt;
       &lt;/LinearLayout&gt;  
      &lt;include layout="@layout/drawer_main"/&gt;
      &lt;/FrameLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>and, finally, drawer_main.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent" &gt;
      &lt;SlidingDrawer xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/drawer" 
          android:handle="@+id/handle"
          android:content="@+id/content" 
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"
          android:background="@null"
  
          android:layout_gravity="bottom"&gt;
  
              &lt;LinearLayout 
                  android:id="@id/content"
                  android:layout_width="fill_parent" 
                  android:layout_height="fill_parent"
                  android:orientation="vertical"&gt;
  
                      &lt;TextView 
                          android:layout_width="fill_parent"
                          android:layout_height="wrap_content" 
                          android:textSize="14dip"
                          android:textStyle="bold|italic"
                          android:background="@android:color/white"
                          android:textColor="@android:color/black"
                          android:text="@string/top_search_results" &gt;
                      &lt;/TextView&gt;
  
                      &lt;View 
                          android:background="@android:drawable/divider_horizontal_bright"
                          android:layout_width="fill_parent"
                          android:layout_height="2dp" &gt;
                      &lt;/View&gt;
  
                      &lt;ListView 
                          android:layout_width="fill_parent"
                          android:layout_height="wrap_content" 
                          android:id="@+id/listview_"
                          android:background="@android:color/black"
                          android:textColor="@android:color/white"
                          android:divider="@android:color/transparent" 
                          android:dividerHeight="2dp" &gt;
                      &lt;/ListView&gt;
  
              &lt;/LinearLayout&gt;
  
              &lt;Button 
                  android:id="@id/handle" 
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" 
                  android:background="@drawable/handle_down_white"&gt;
              &lt;/Button&gt;
  
      &lt;/SlidingDrawer&gt;
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>Sorry that this is so lengthy. Any assistance will be greatly appreciated.</p>