【Android源码 栏目提醒】:网学会员--在 Android源码 编辑为广大网友搜集整理了:[SkeletonApp工程][android源码][SkeletonActivity java] - 开发文档绩等信息,祝愿广大网友取得需要的信息,参考学习。
/ Copyright C 2007 The Android Open Source Project Licensed under the Apache License Version 2.0 the License you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing software distributed under the License is distributed on an AS IS BASIS WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied. See the License for the specific language governing permissions and limitations under the License. / package com.example.android.skeletonapp import android.app.Activity import android.os.Bundle import android.view.KeyEvent import android.view.Menu import android.view.MenuItem import android.view.View import android.view.View.OnClickListener import android.widget.Button import android.widget.EditText / 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. / public class SkeletonActivity extends Activity static final private int BACK_ID Menu.FIRST static final private int CLEAR_ID Menu.FIRST 1 private EditText mEditor public SkeletonActivity / Called with the activity is first created. / Override public void onCreateBundle savedInstanceState super.onCreatesavedInstanceState // Inflate our UI from its XML layout description. setContentViewR.layout.skeleton_activity // Find the text editor view inside the layout because we // want to do various programmatic things with it. mEditor EditText findViewByIdR.id.editor // Hook up button presses to the appropriate event handler. Button findViewByIdR.id.back.setOnClickListenermBackListener Button findViewByIdR.id.clear.setOnClickListenermClearListener mEditor.setTextgetTextR.string.main_label / Called when the activity is about to start interacting with the user. / Override protected void onResume super.onResume / Called when your activitys options menu needs to be created. / Override public boolean onCreateOptionsMenuMenu menu super.onCreateOptionsMenumenu // 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.add0 BACK_ID 0 R.string.back.setShortcut0 b menu.add0 CLEAR_ID 0 R.string.clear.setShortcut1 c return true / Called right before your activitys option menu is displayed. / Override public boolean onPrepareOptionsMenuMenu menu super.onPrepareOptionsMenumenu // Before showing the menu we need to decide whether the clear // item is enabled depending on whether there is text to clear. menu.findItemCLEAR_ID.setVisiblemEditor.getText.length 0 return true / Called when a menu item is selected. / Override public boolean onOptionsItemSelectedMenuItem item switch item.getItemId case BACK_ID: finish return true case CLEAR_ID: mEditor.setText return true return super.onOptionsItemSelecteditem / A call-back for when the user presses the back button. / OnClickListener mBackListener new OnClickListener public void onClickView v finish / A call-back for when the user presses the clear button. / OnClickListener mClearListener new OnClickListener public void onClickView v mEditor.setText