MyMenuset GroupCheckable MenuCategorysecondaryfalsefalse

this.appendMenuItemText(item);

//should return true if the menu item //is handled return true;

Listing 5-11 also exercises operations on menus at the group level; calls to these methods are highlighted in bold. The code also logs the details about the clicked menu item to the TextView. Listing 5-12 shows some utility functions to write to the TextView. Notice an additional method on a MenuItem to get its title.

Listing 5-12. Utility Functions to Write to the Debug TextView

//Given a string of text append it to the TextView private void appendText(String text) {

TextView tv = (TextView)this.findViewByld(R.id.textViewld); tv.setText(tv.getText() + text);

//Given a menu item append its title to the TextView private void appendMenuItemText(MenuItem menuItem) { String title = menuItem.getTitle().toString(); TextView tv = (TextView)this.findViewByld(R.id.textViewld); tv.setText(tv.getText() + "\n" + title);

//Empty the TextView of its contents private void emptyText() {

TextView tv = (TextView)this.findViewByld(R.id.textViewld); tv.setText("");

0 0

Post a comment