diff --git a/app/src/main/java/org/ntlab/amaryllis/client/MainActivity.java b/app/src/main/java/org/ntlab/amaryllis/client/MainActivity.java index b503b4c..299cfff 100644 --- a/app/src/main/java/org/ntlab/amaryllis/client/MainActivity.java +++ b/app/src/main/java/org/ntlab/amaryllis/client/MainActivity.java @@ -24,6 +24,8 @@ import android.os.Debug; import android.provider.Settings; import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; import android.widget.Toast; import com.google.android.material.bottomnavigation.BottomNavigationView; @@ -50,6 +52,8 @@ LocationManager locationManager; private ArrayList listeners = new ArrayList<>(); private HashMap categories; + ArrayList checkedList = new ArrayList<>(); + HashMap menuItemMap = new HashMap<>(); @Override protected void onCreate(Bundle savedInstanceState) { @@ -197,4 +201,39 @@ return categories.get(cid); } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.nav_drawer_menu, menu); + + //カテゴリーの数だけitemを定義 + for(Category category : categories.values()){ + String name = category.getName(); + String cid = category.getcId(); + MenuItem newItem = menu.add(Menu.NONE, Menu.NONE, Menu.NONE, name); + menuItemMap.put(newItem.getItemId(),cid); + newItem.setCheckable(true); + newItem.setChecked(true); + checkedList.add(cid); + } + return true; + } + + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + String cid = menuItemMap.get(item.getItemId()); + + item.setChecked(!item.isChecked()); + if(item.isChecked()){ + checkedList.remove(cid); + }else{ + checkedList.add(cid); + } + return super.onOptionsItemSelected(item); + } + + public ArrayList getCheckedCidList() { + return checkedList; + } + } \ No newline at end of file