Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7897825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:16:04+00:00 2026-06-03T08:16:04+00:00

I am working on an Android mapping app that allows a user to type

  • 0

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.

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.

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.

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.

(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.)

Here is the code that calls my SlidingDrawer:

            //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 < target.length; i++){
            drawerIntent.putExtra("target" + Integer.toString(i), target[i]);
        }
        this.startActivity(drawerIntent);

This is the code in my SlidingDrawer class (extends Activity) that fills the list inside the drawer:

    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<MyData> myDataList = new ArrayList<MyData>();
            myData = new MyData[numberOfTargets];

            for(int i = 0; i < 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);
                }
            });

My layout files:

main.xml:

    <?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="vertical" >

<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">
        <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" />    
        <Button 
            android:id="@+id/geocode_button"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" 
            android:text="@string/goLabel" />
    </LinearLayout>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" >           
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
        <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"/>
     </LinearLayout>  
    <include layout="@layout/drawer_main"/>
    </FrameLayout>
</LinearLayout>

and, finally, drawer_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" >
    <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">

            <LinearLayout 
                android:id="@id/content"
                android:layout_width="fill_parent" 
                android:layout_height="fill_parent"
                android:orientation="vertical">

                    <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" >
                    </TextView>

                    <View 
                        android:background="@android:drawable/divider_horizontal_bright"
                        android:layout_width="fill_parent"
                        android:layout_height="2dp" >
                    </View>

                    <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" >
                    </ListView>

            </LinearLayout>

            <Button 
                android:id="@id/handle" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" 
                android:background="@drawable/handle_down_white">
            </Button>

    </SlidingDrawer>
</FrameLayout>

Sorry that this is so lengthy. Any assistance will be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:16:05+00:00Added an answer on June 3, 2026 at 8:16 am

    The solution I opted for is programmatically a bit less than ideal, but the layout works well. Since I knew I wouldn’t have more than 3 results, I just changed my layout to include (up to) 3 small TextViews under my search bar and (sadly) got rid of the SlidingDrawer altogether. When the results come back, I populate as many TextViews as necessary, each with an onClickListener. It won’t scale well, and everything is hard-coded; but it works. I may try to improve upon this solution as I learn more about Android.

    new Layout:

    <?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="vertical" >
    
    <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">
    
    
            <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" />
    
            <Button 
                android:id="@+id/geocode_button"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1" 
                android:text="@string/goLabel" />
    
        </LinearLayout>
    
        <TextView 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:textSize="13dip"
                android:textStyle="bold|italic"
                android:background="@android:color/black"
                android:textColor="@android:color/white"
                android:id="@+id/search_results_header" >
        </TextView>
    
        <View   android:id="@+id/bar_over_one"       
                android:layout_width="fill_parent" 
                android:layout_height="1dp" 
                android:background="#DADADA" />
    
        <TextView 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:textSize="11dip"
                android:background="@android:color/black"
                android:textColor="@android:color/white"
                android:id="@+id/line_one" >
        </TextView>
    
        <View   android:id="@+id/bar_over_two"       
                android:layout_width="fill_parent" 
                android:layout_height="1dp" 
                android:background="#DADADA" />
    
        <TextView 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:textSize="11dip"
                android:background="@android:color/black"
                android:textColor="@android:color/white"
                android:id="@+id/line_two" >
        </TextView>
    
        <View   android:id="@+id/bar_over_three"       
                android:layout_width="fill_parent" 
                android:layout_height="1dp" 
                android:background="#DADADA" />
    
        <TextView 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:textSize="11dip"
                android:background="@android:color/black"
                android:textColor="@android:color/white"
                android:id="@+id/line_three" >
        </TextView>
    
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >
            <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="0fmGmyFrFDUrPGrwXR_scZZxVx6CkSdK-sys-Qw"/>
         </LinearLayout>  
    </LinearLayout>
    

    new code:

        private void populateList(int numberOfTargetsForList){
        TextView header = (TextView) findViewById(R.id.search_results_header);
        header.setText("Top Search Results");
    
        int i = 0;
        //first line in list
        barOverOne.setVisibility(View.VISIBLE);
        String ratingAndDistance = "";
        if(target[i].getRating().equals("Not Yet Rated")){
            ratingAndDistance = "      " + target[i].getRating() + "                           " + 
                    Double.toString((Math.round(target[i].getDistance()*100.0))/100.0) + " miles";
        }
        else{
            ratingAndDistance = "     rating: " + target[i].getRating() + "/5 stars                    " + 
                    Double.toString((Math.round(target[i].getDistance()*100.0))/100.0) + " miles";  
        }
        String detailsForLineOne = (Integer.toString(i + 1) + ": " + target[i].getName() + ", " + target[i].getVicinity()) + "\n" + ratingAndDistance;
        TextView lineOne = (TextView) findViewById(R.id.line_one);
        lineOne.setText(detailsForLineOne);
        lineOne.setOnClickListener(this);
    
        i++;
    

    …(similar blocks handle cases of i = 1 and i =2)

    Finally, in my onClick() method:

        case R.id.line_one:{
        String locForURL = "origin=" + Double.toString(lat/1000000.0) + 
                "," + Double.toString(lon/1000000.0) + "&destination=" + 
                Double.toString(target[0].getLat()/1000000.0) + "," + 
                Double.toString(target[0].getLon()/1000000.0);
        Intent intent = new Intent(this, ParsingXMLDirectionsWithListView.class);
            intent.putExtra("dirTitle", target[0].getName()+ " (" +
                Double.toString((Math.round(target[0].getDistance()*100.0))/100.0) + " miles)");
            intent.putExtra("locForURL", locForURL);
        this.startActivity(intent); 
        break;
    }//line_one
    

    …(similar blocks for lines two and three)

    Not perfect, but oh well. At least looks pretty good from the user’s end, and I was never going to meet my deadline by continuing down the SlidingDrawer route. Maybe when I have some more free time I’ll see if I can figure that out….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a working Android tuner project app that I want to use as
Im working with Android 2.1, RoboGuice 1.1 and Guice 2.0 (without aop). My app
I am working on Android database type application. We need to show some reports.
I am working on android geolocation application in that I have added marker for
I'm working on android app development in which how get profiling information like Data
I am working in Android. I need to convert byte[] to Buffer type. In
am working an android native app , and searching for a way to develop
I already have a working android app with several persisted objects/classes. But what if
I have a working android app using TextView, some formatting (line breaks, rows of
I have been working with android for a little while now and feel pretty

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.