0

I am using a ListPopup Window on a Map in Android Studio to show a list of customized marker names. These markers are stored in an arrayList of a class that keeps the name and the coordinates. The idea is to move the map camera in position over the marker when they are clicked in the popup window. For whatever reason when I set the OnItemClickListener() nothing happens when I click an Item.

Here is the XML:

<ImageButton
        android:id="@+id/MENU"
        android:layout_width="40dp"
        android:layout_height="45dp"
        android:src="@drawable/ic_drawer"
        android:layout_gravity="start"
        android:onClick="homeMenuHandler"/>

Here is my ButtonHandler code:

ArrayList homeArrayList;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    homeArrayList = new ArrayList<>();
}

public void homeButtonHandler(View view) {

    ListPopupWindow homeMenuWindow = new ListPopupWindow(this);
    ArrayList<String> homeArray = new ArrayList<>();

    //homeArrayList is list of marker names with coordinates
    for (int i = 0; i < homeArrayList.size(); i++) {
            homeArray.add(homeArrayList.get(i).getName());
    }

    homeMenuWindow.setAdapter(new ArrayAdapter<String>(this,
    android.R.layout.simple_list_item_1, homeArray));

    homeMenuWindow.setWidth(200);
    homeMenuWindow.setAnchorView(view);
    homeMenuWindow.show();
    homeMenuWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            LatLng zoomTo;
            //Gets the coord of the marker 
            zoomTo = homeArrayList.get(position).getCoord();
             Log.d("Todd", "Test"+ position + " " + parent + " " + id + " " + view);
            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(zoomTo, 15));
            homeMenuWindow.dismiss();
            }
        }
    );
}

I cannot even get a readout on my LogCat. Can anyone think of something I am missing? I can't find any tutorials on the ListPopup Window anywhere on the web. Any Help would be much appreciated.

Mattia Maestrini
  • 32,270
  • 15
  • 87
  • 94
T_will
  • 11

1 Answers1

0

Assuming "zoomTo" is retrieved correctly, if you even can't get anything from logcat the problem should be on the click listener. You can try to add a toast when clicking on an item, if the toast is shown, the clicklistener works, otherwise you should check some examples on ListPopupWindow itemclicklistener!

The move camera methods seems correct anyway

N Dorigatti
  • 3,482
  • 2
  • 22
  • 33
  • I have the move camera methods working in other places in my App. I am not worried about that working. I have tried to look online for OnItemClickListener for the ListPopupWindow and I can't find what I am doing wrong. – T_will Apr 20 '15 at 19:21
  • Honestly i can't get what is wrong,the only thing you can try is to use onItemSelectedListener instead... – N Dorigatti Apr 21 '15 at 17:06