FileDocCategorySizeDatePackage
SkeletonActivity.javaAPI DocAndroid 1.5 API4113Wed May 06 22:41:08 BST 2009com.example.android.skeletonapp

SkeletonActivity

public class SkeletonActivity extends android.app.Activity
This class provides a basic demonstration of how to write an Android activity. Inside of its window, it places a single view: an EditText that displays and edits some internal text.

Fields Summary
private static final int
BACK_ID
private static final int
CLEAR_ID
private android.widget.EditText
mEditor
android.view.View.OnClickListener
mBackListener
A call-back for when the user presses the back button.
android.view.View.OnClickListener
mClearListener
A call-back for when the user presses the clear button.
Constructors Summary
public SkeletonActivity()

    
      
    
Methods Summary
public voidonCreate(android.os.Bundle savedInstanceState)
Called with the activity is first created.

        super.onCreate(savedInstanceState);

        // Inflate our UI from its XML layout description.
        setContentView(R.layout.skeleton_activity);

        // Find the text editor view inside the layout, because we
        // want to do various programmatic things with it.
        mEditor = (EditText) findViewById(R.id.editor);

        // Hook up button presses to the appropriate event handler.
        ((Button) findViewById(R.id.back)).setOnClickListener(mBackListener);
        ((Button) findViewById(R.id.clear)).setOnClickListener(mClearListener);
        
        mEditor.setText(getText(R.string.main_label));
    
public booleanonCreateOptionsMenu(android.view.Menu menu)
Called when your activity's options menu needs to be created.

        super.onCreateOptionsMenu(menu);

        // We are going to create two menus. Note that we assign them
        // unique integer IDs, labels from our string resources, and
        // given them shortcuts.
        menu.add(0, BACK_ID, 0, R.string.back).setShortcut('0", 'b");
        menu.add(0, CLEAR_ID, 0, R.string.clear).setShortcut('1", 'c");

        return true;
    
public booleanonOptionsItemSelected(android.view.MenuItem item)
Called when a menu item is selected.

        switch (item.getItemId()) {
        case BACK_ID:
            finish();
            return true;
        case CLEAR_ID:
            mEditor.setText("");
            return true;
        }

        return super.onOptionsItemSelected(item);
    
public booleanonPrepareOptionsMenu(android.view.Menu menu)
Called right before your activity's option menu is displayed.

        super.onPrepareOptionsMenu(menu);

        // Before showing the menu, we need to decide whether the clear
        // item is enabled depending on whether there is text to clear.
        menu.findItem(CLEAR_ID).setVisible(mEditor.getText().length() > 0);

        return true;
    
protected voidonResume()
Called when the activity is about to start interacting with the user.

        super.onResume();