0

I am trying to make an android weather app in which I use a side menu to add and display cities. This is the xml for the side menu:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">

<group android:checkableBehavior="single">
    <item
        android:id="@+id/cityAdd"
        android:icon="@drawable/ic_menu_camera"
        android:title="Add City" />
    <menu android:id="@+id/sideContainer" android:title="Cities">

        <listView
            android:id="@+id/cityList"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="5dp"
           >

        </listView>


    </menu>

 </group>

</menu>

This result in a side menu looking like this :

sidemenu

I then created an arraylist named citites full of city objects :

public ArrayList < city > cities = new ArrayList < > ();


   public class city {
    int temperature;
    String conditions;
    String town;
    String country;
    String state;

    public Object requestData(String url) {
        final RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
        JsonObjectRequest objectRequest = new JsonObjectRequest(
                Request.Method.GET,
                url,
                null,
                new Response.Listener < JSONObject > () {
                    @Override
                    public void onResponse(JSONObject response) {
                        sharedResponse(response.toString());
                    }

                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {

                    }
                }
        );
        requestQueue.add(objectRequest);

        return null;
    }

}

I would like to use an arrayadapter to fill the sidemenu full of dynamically created cities. I then want to have onclick handles for each of these city items that will select the city, close the sidemenu, and then display information back on the main activity that the sidemenu overlays on. How would I go about creating this arrayadapter? I am new to all of this so please be patient with me :) . Thanks!

1 Answers1

0

You can't use listview inside menu resources. You can try this code

final Menu menu = navigationView.getMenu();

for (int i = 1; i <= 10; i++){ 
    menu.add("Runtime item "+ i);
}

reference

Suleyman
  • 2,309
  • 2
  • 12
  • 28
  • Thank you for the reply! This is a similar approach I had taken in the beginning. How could I add onclick handlers to each item added? – Brayden Brekke May 11 '18 at 03:48