I am creating a pop up menu dynamically, where the items will be populated from the web service.
The situation is, the parsing has been in the MainActivity.java
, but the Pop up menu is inside the BaseAdapter.java
class. I am adding all the menu items inside an array inside the MainActivity.java
.Please refer the code below:
try {
JSONArray jsonArray = new JSONArray(menuItemsResponse.toString());
for (int i = 0; i < jsonArray.length(); i++){
JSONObject object = jsonArray.getJSONObject(i);
String strMenuItemNames = object.getString("Name");
listMenuItems.add(strMenuItemNames);
}
} catch (Exception e) {
e.printStackTrace();
}
I am adding items inside List<String> listMenuItems
with listMenuItems.add(strMenuItemNames)
.
Now, I want to access this listMenuitems
from BaseAdapter class. Below is my code for Pop Up menu inside getView()
method in BaseAdapter class:
PopupMenu popupMenu = new PopupMenu(activity, imgDropDown);
popupMenu.getMenu().add() // array to be added here
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener({
// on click events for each item
});
Anyone with solutions please respond.
Thanks in advance!