Code example for SubMenu

Methods: add, findItem, setGroupCheckable, setGroupEnabled

0
		 
		{ 
			int groupNum = 20;
			SubMenu sync = menu.addSubMenu(Menu.NONE, groupNum, 20, "Auto Refresh"); //getItem().
			//sync.setIcon(android.R.drawable.stat_notify_sync); 
			sync.add(groupNum, 0, 0, "On Application Startup");
			sync.add(groupNum, 30, 2, "30 Minutes");
			sync.add(groupNum, 60, 3, "Hourly");
			sync.add(groupNum, 60 * 2, 4, "2 Hours");
			sync.add(groupNum, 60 * 3, 5, "3 Hours");
			sync.add(groupNum, 60 * 4, 6, "4 Hours");
			sync.add(groupNum, 60 * 6, 7, "6 Hours");
			sync.add(groupNum, 60 * 8, 8, "8 Hours");
			sync.add(groupNum, 60 * 12, 9, "12 Hours");
			sync.add(groupNum, 60 * 24, 10, "Daily");
			sync.add(groupNum, 60 * 24 * 2, 11, "2 Days");
			sync.add(groupNum, 60 * 24 * 4, 12, "4 Days");
			sync.add(groupNum, 60 * 24 * 7, 13, "Weekly");
			int syncInterval = mSharedPreferences.contains("sync") ? mSharedPreferences.getInt("sync",300) : 300;
			sync.setGroupCheckable(groupNum, true, true);
			sync.setGroupEnabled(groupNum, true);
			 
			MenuItem activeitem = null;
			activeitem = sync.findItem(syncInterval);
			if( activeitem == null ){
				if( syncInterval > 0 ){
					sync.add(groupNum, syncInterval, 1, syncInterval + " Minutes");
				}else{ 
					syncInterval = 30; // Must exist.
				} 
				activeitem = sync.findItem(syncInterval);
			} 
			activeitem.setChecked(true);
		} 
		 
		//sync.findItem(11).setChecked(true);