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

  • SEARCH
  • Home
  • 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 8279211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:15:27+00:00 2026-06-08T09:15:27+00:00

When setting up my listview,I set an Arraylist of OverlayItems as adapter for listview

  • 0

When setting up my listview,I set an Arraylist of OverlayItems as adapter for listview because when I click on the items in the list, I want to acces the geopoints that come with Overlayitems.

Yet this solution gives a rather ugly listview, because it doesn’t show the different titles of the Overlayitems, but something like OverlayItem@jiozl26.

Does anybody know what the easiest way to solve this(both showing the title, and still being able to acces the geopoints?) I think I should do this with a custom listview, but I’m not sure that this is the easiest/most efficient way.

adapter = new ArrayAdapter<OverlayItem>(this, android.R.layout.simple_list_item_1, custom.pinpoints);
        listView.setAdapter(adapter);

==>The entire code:

public class Main extends MapActivity implements OnTabChangeListener{
    /** Called when the activity is first created. */
    private static final String LIST_TAB_TAG = "List";
    private static final String MAP_TAB_TAG = "Map";

    MapView map;
    ListView listView;

    TabHost tabHost;

    long start;
    long stop;
    int x, y;

    MyLocationOverlay compass;
    MyLocationOverlay MyLoc;
    MapController controller;

    GeoPoint touchedPoint;
    Drawable d;
    List<Overlay> overlayList;
    CustomPinpoint custom;

    static Context context;
    ArrayAdapter<OverlayItem> adapter;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);

        tabHost = (TabHost) findViewById(android.R.id.tabhost);
        tabHost.setup();

        context = getApplicationContext();

        listView = (ListView) findViewById(R.id.list);
        listView.setEmptyView((TextView) findViewById(R.id.empty));
        d = getResources().getDrawable(R.drawable.ic_launcher);
        custom = new CustomPinpoint(d,Main.this);
        listView.setLongClickable(true);
        adapter = new ArrayAdapter<OverlayItem>(this, android.R.layout.simple_list_item_1, custom.pinpoints);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                GeoPoint geoPoint = ((OverlayItem) listView.getAdapter().getItem(position)).getPoint();
                if(geoPoint != null) {

                    map.getController().animateTo(geoPoint);

                    tabHost.setCurrentTab(1);
                        }
                    }
            });

        listView.setOnItemLongClickListener(new OnItemLongClickListener() {

            public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
                final AlertDialog alert3 = new AlertDialog.Builder(Main.this).create();     
                alert3.setTitle("Pick an option.");
                alert3.setButton(DialogInterface.BUTTON_POSITIVE,"Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub

                    }
            });
                alert3.setButton(DialogInterface.BUTTON_NEUTRAL,"Modify", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        LayoutInflater factory = LayoutInflater.from(context);
                        View promptsView = factory.inflate(R.layout.prompts, null);

                        final AlertDialog alert4 = new AlertDialog.Builder(Main.this).create();
                        alert4.setView(promptsView);
                            final EditText userInput1 = (EditText) promptsView.findViewById(R.id.editTextInput1);
                            final EditText userInput2 = (EditText) promptsView.findViewById(R.id.editTextInput2);
                            userInput1.setInputType(InputType.TYPE_CLASS_TEXT);
                            userInput1.setCursorVisible(true);
                            userInput2.setInputType(InputType.TYPE_CLASS_TEXT);
                            userInput2.setCursorVisible(true);
                            alert4.setButton (DialogInterface.BUTTON_NEGATIVE,"Save", new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                    custom.modifyPinpoint(userInput1.getText().toString(), userInput2.getText().toString(),position);
                                                    map.postInvalidate(); 
                                                        }
                            });         

                            alert4.setButton(DialogInterface.BUTTON_POSITIVE, "Cancel", new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                        }                       
                                });     
                    alert4.show();

                    }
            });
                alert3.setButton(DialogInterface.BUTTON_NEGATIVE,"Delete", new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int which) {
                            custom.deletePinpoint(position);
                            adapter.notifyDataSetChanged();
                        }
                });
        alert3.show();
        return true;
            }
            });


        map = (MapView) findViewById(R.id.mapview);
        map.setBuiltInZoomControls(true);
        map.postInvalidate();

        Touch t = new Touch();
        overlayList = map.getOverlays();
        overlayList.add(t);
        compass = new MyLocationOverlay(Main.this, map);
        overlayList.add(compass);
        controller = map.getController();



        MyLoc = new MyLocationOverlay(Main.this, map);
        overlayList.add(MyLoc);
        map.postInvalidate();
        MyLoc.runOnFirstFix(new Runnable() {
            public void run() {
                map.getController().animateTo(MyLoc.getMyLocation());
                }
        }); 

        tabHost.addTab(tabHost.newTabSpec(LIST_TAB_TAG).setIndicator("List").setContent(new TabContentFactory() {
            public View createTabContent(String arg0) {
                return listView;
            }
        }));
        tabHost.addTab(tabHost.newTabSpec(MAP_TAB_TAG).setIndicator("Map").setContent(new TabContentFactory() {
            public View createTabContent(String arg0) {
                return map;
            }
        }));

        tabHost.setCurrentTab(1);
        tabHost.setCurrentTab(0);


    }



    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        compass.disableCompass();
        super.onPause();
        MyLoc.disableMyLocation();
        finish();
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        compass.enableCompass();
        super.onResume();
        MyLoc.enableMyLocation();

    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }



    class Touch extends Overlay {
        public boolean onTouchEvent(MotionEvent e, MapView m) {
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                start = e.getEventTime();
                x = (int) e.getX();
                y = (int) e.getY();
                touchedPoint = map.getProjection().fromPixels(x, y);    
                        }
            if (e.getAction() == MotionEvent.ACTION_UP) {
                stop = e.getEventTime();
                        }
            if (stop - start > 1200) {
                final AlertDialog alert = new AlertDialog.Builder(Main.this).create();
                alert.setTitle("Pick an option.");
                alert.setButton(DialogInterface.BUTTON_POSITIVE,"Place a pinpoint.", new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int which) {

                                    LayoutInflater factory = LayoutInflater.from(context);
                                    View promptsView = factory.inflate(R.layout.prompts, null);

                                    final AlertDialog alert2 = new AlertDialog.Builder(Main.this).create();
                                    alert2.setView(promptsView);
                                        final EditText userInput1 = (EditText) promptsView.findViewById(R.id.editTextInput1);
                                        final EditText userInput2 = (EditText) promptsView.findViewById(R.id.editTextInput2);
                                        userInput1.setInputType(InputType.TYPE_CLASS_TEXT);
                                        userInput1.setCursorVisible(true);
                                        userInput2.setInputType(InputType.TYPE_CLASS_TEXT);
                                        userInput2.setCursorVisible(true);
                                        alert2.setButton (DialogInterface.BUTTON_NEGATIVE,"Save", new DialogInterface.OnClickListener() {

                                                        public void onClick(DialogInterface dialog, int whichButton) {
                                                                OverlayItem overlayItem = new OverlayItem(touchedPoint, userInput1.getText().toString(), userInput2.getText().toString());
                                                                custom.insertPinpoint(overlayItem);
                                                                overlayList.add(custom);
                                                                map.postInvalidate(); 
                                                                    }
                                            });         

                                        alert2.setButton(DialogInterface.BUTTON_POSITIVE, "Cancel", new DialogInterface.OnClickListener() {

                                                        public void onClick(DialogInterface dialog, int whichButton) {
                                                                    }                       
                                            });     
                                alert2.show();
                                }
                });  

                alert.setButton(DialogInterface.BUTTON_NEUTRAL,"Get address.",new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog,int which) {
                                // TODO Auto-generated method stub

                                    Geocoder geocoder = new Geocoder(getBaseContext(), Locale.getDefault());
                                        try{

                                                List<Address> address = geocoder.getFromLocation(touchedPoint.getLatitudeE6() /1E6, touchedPoint.getLongitudeE6()/1E6, 1);                          

                                                if (address.size() > 0){
                                                    String display = "";                                                
                                                    for (int i = 0; i < address.get(0).getMaxAddressLineIndex(); i++){

                                                        display += address.get(0).getAddressLine(i) + "\n";
                                                        }               
                                                    Toast t3 = Toast.makeText(getBaseContext(), display, Toast.LENGTH_LONG);
                                                    t3.show();
                                                }

                                        } catch (IOException e) {
                                            // TODO Auto-generated catch block
                                            e.printStackTrace();
                                        }finally{

                                        }

                            }
                });

                alert.setButton(DialogInterface.BUTTON_NEGATIVE,"Toggle View", new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int which) {
                                    // TODO Auto-generated method stub

                                        if (map.isSatellite()){
                                            map.setSatellite(false);

                                            }else{

                                            map.setSatellite(true);
                                            }


                                }
                });
                alert.show();
                return true;
            }
            return false;
        }
    }




     public void gpsCurrentLocation()
     {

         tabHost.setCurrentTab(1);
         GeoPoint p = MyLoc.getMyLocation();
         if (p == null){
             Toast.makeText(Main.this, "Your location wasn't found.", Toast.LENGTH_SHORT).show();
         }
         else{
         map.getController().animateTo(p);
         }

     }


    // Menu XML file (menu.xml)
    @Override
     public boolean onCreateOptionsMenu(Menu menu)
     {
     MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.map_main, menu);

               return true;
     }

    @Override
     public boolean onOptionsItemSelected(MenuItem item)
     {

     switch (item.getItemId())
     {
     case R.id.my_location:
     Toast.makeText(Main.this, "Moving To Current location", Toast.LENGTH_SHORT).show();
     gpsCurrentLocation();
     return true;
     case R.id.menu_clear:   
         custom.clearPinpoint();
         adapter.notifyDataSetChanged();

     }

    return false;
     }



    public void onTabChanged(String tabId) {
        // TODO Auto-generated method stub

    }

}

  • 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-08T09:15:29+00:00Added an answer on June 8, 2026 at 9:15 am

    Just override the toString() method of your subclass of OverlayItem in order to return the title of this object.

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

Sidebar

Related Questions

I want to set a background image to my listview so that regardless of
Below is my code for setting up a listview. I want to implement a
I'm setting layout animation to list view (my items are dropping down). In list
I have a ListView with a custom footer set via list.addFooterView(getLayoutInflater().inflate(R.layout.list_footer_view, null, true), null,true);
I want to disable items in a ListView . First, I tried to use
Hey all, I have a winforms virtualized Listview that i want to be able
I have created a listview that sits inside a larger activity (the list view
i am making listview of many column and i want to make the list
I am trying to set On Click Listener on the List view. I have
I'm trying to populate a ListView with an ArrayList> using a base adapter. The

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.