Code example for SimpleCursorAdapter

Methods: isEmpty, getCursor

0
		alert.show();
	} 
 
	protected void deleteSession(long id) {
		mDb.deleteSession(id);
		mExistingSessionsAdapter.getCursor().requery();
		updateUI(); 
	} 
 
	protected void sessionListSelectionChanged() { 
		if (mDeleteGameItem!=null)
			mDeleteGameItem.setEnabled(mExistingSessionsList.getSelectedItem() != null);
	} 
 
	/** 
	 * Returns true if the button is in start mode, false otherwise. 
	 */ 
	protected boolean addPlayerOrStartButtonIsStartMode() { 
		// allow to start a new game only if min. 2 players 
		return (mNewPlayerNameText.getText().toString().length() == 0 &&
				mListOfPlayersAdapter.getCount() >= 2);
	} 
 
	protected void updateAddPlayerOrStartButton() { 
		Drawable drawable = null;
		if (addPlayerOrStartButtonIsStartMode()) 
			drawable = getResources().getDrawable(R.drawable.ic_menu_play_clip_small);
		else 
			drawable = getResources().getDrawable(R.drawable.ic_menu_add_small);
		mAddNewPlayerOrStartButton.setCompoundDrawablesWithIntrinsicBounds(
				drawable, null, null, null);
	} 
 
	protected void updateUI() { 
		// Hide "existing session" list once the user starts to add 
		// players for a new game. This is mostly for layout reasons, 
		// because we apparently can't really have two lists in the 
		// same screen unless both are fixed height (the first 
		// list would push elements below it out of the screen) (*). 
		// 
		// So we basically hide the session list when the player 
		// starts to use the player list. 
		// 
		// (*) We could possible work with a parent ScrollView and 
		// making both lists wrap_content, i.e. the whole screen 
		// would scroll, through both lists and the controls in 
		// between. This wouldn't make for very good user interface 
		// though, since the user would be responsible to scrolling 
		// the "player name" TextEdit into view when he wants to use it. 
		if (!mListOfPlayersAdapter.isEmpty()) {
			LinearLayout.LayoutParams params;
			params = (LinearLayout.LayoutParams) mExistingPlayersList.getLayoutParams();
			params.weight = 1;
			mExistingPlayersList.setLayoutParams(params);
 
			mExistingSessionsPanel.setVisibility(View.GONE);
		} else { 
			LinearLayout.LayoutParams params;
			params = (LinearLayout.LayoutParams) mExistingPlayersList.getLayoutParams();
			params.weight = 0;
			mExistingPlayersList.setLayoutParams(params);
 
			// Also hide the whole sessions panel if there aren't any sessions 
			if (mExistingSessionsAdapter.isEmpty())
				mExistingSessionsPanel.setVisibility(View.GONE);
			else 
				mExistingSessionsPanel.setVisibility(View.VISIBLE);
		} 
 
		// Show/hide/enable menu items depending on the features 
		// and controls  currently visible. 
		if (mDeleteGameItem != null) {   // Menu might not have been created yet
			boolean editingPlayers = !mListOfPlayersAdapter.isEmpty();
			boolean sessionsExist = !mExistingSessionsAdapter.isEmpty();
			mDeleteGameItem.setVisible(!editingPlayers);
			mClearGamesItem.setVisible(!editingPlayers);
			mClearGamesItem.setEnabled(sessionsExist);
			mClearPlayersItem.setVisible(editingPlayers);
		}