It is necessary that when selecting one category, elements of this category are shown. That is, there is a conditional menu where you can select it. You can probably change the activations relative to the category, but this is not rational. The main problem is that if you change the ArrayList in the adapter, the sheet in the main activation also changes, and everything is updated and you can’t save the original number of elements and the list elements themselves.
Here are the drop down menus.
public void showPopup() { View menuItemView = findViewById(R.id.action_sort); PopupMenu popup = new PopupMenu(MainActivity.this, menuItemView); MenuInflater inflate = popup.getMenuInflater(); inflate.inflate(R.menu.popup, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { ArrayList<Item> list = new ArrayList<Item>(); switch (item.getTitle().toString()) { case "Zerg": list.clear(); for (Item item1 : array_build) if (item1.Race == 0) list.add(0, item1); break; case "Protoss": list.clear(); for (Item item1 : array_build) if (item1.Race == 1) list.add(0, item1); break; case "Terran": list.clear(); for (Item item1 : array_build) if (item1.Race == 2) list.add(0, item1); break; } adapter.listChange(list); return true; } }); popup.show(); } Adapter and list update method. Actually a very simple adapter. listChange change this list to come.
public class ItemAdapter extends BaseAdapter { Context cnt; LayoutInflater layoutInflater; ArrayList<Item> itemlist; ItemAdapter(Context cnt, ArrayList<Item> itemlist) { this.cnt = cnt; this.itemlist = itemlist; layoutInflater = (LayoutInflater) cnt.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public int getCount() { return itemlist.size(); } @Override public Item getItem(int position) { return itemlist.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; if (view == null) { view = layoutInflater.inflate(R.layout.row_style, parent, false); } Item item = getItem(position); ((TextView) view.findViewById(R.id.txtTitle)).setText(item.Title); ImageView image = (ImageView) view.findViewById(R.id.ImageViewRace); switch (item.Race) { case 0: image.setBackgroundResource(R.drawable.z); break; case 1: image.setBackgroundResource(R.drawable.p); break; case 2: image.setBackgroundResource(R.drawable.t); break; default: image.setBackgroundResource(R.color.black); }; return view; } public void listChange(ArrayList<Item> list){ itemlist.clear(); itemlist.addAll(list); this.notifyDataSetChanged(); } public void add(Item item1){ itemlist.add(0,item1); this.notifyDataSetChanged(); } public void remove(int position){ itemlist.remove(position); this.notifyDataSetChanged(); } } And this is what happens when you select one of 4 categories (Chose Protoss): 
And if you choose another one, for obvious reasons, we only have this list, and the old one where all the other elements were stored disappeared, how to keep that list after changes in the adapter. The problem itself, I just write 3 denb, a beginner. If that all the items in the database are stored. Chose Zerg: