zoukankan      html  css  js  c++  java
  • Android 简单案例:onSaveInstanceState 和 onRestoreInstanceState

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.TextView;
    
    public final class MultiRes extends Activity {
    
        private int mCurrentPhotoIndex = 0;
        private int[] mPhotoIds = new int[] { R.drawable.sample_0,
                R.drawable.sample_1, R.drawable.sample_2, R.drawable.sample_3,
                R.drawable.sample_4, R.drawable.sample_5, R.drawable.sample_6,
                R.drawable.sample_7 };
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            showPhoto(mCurrentPhotoIndex);
    
            // Handle clicks on the 'Next' button.
            Button nextButton = (Button) findViewById(R.id.next_button);
            nextButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    mCurrentPhotoIndex = (mCurrentPhotoIndex + 1)
                            % mPhotoIds.length;
                    showPhoto(mCurrentPhotoIndex);
                }
            });
        }
    
        @Override
        protected void onSaveInstanceState(Bundle outState) {
            outState.putInt("photo_index", mCurrentPhotoIndex);
            super.onSaveInstanceState(outState);
        }
    
        @Override
        protected void onRestoreInstanceState(Bundle savedInstanceState) {
            mCurrentPhotoIndex = savedInstanceState.getInt("photo_index");
            showPhoto(mCurrentPhotoIndex);
            super.onRestoreInstanceState(savedInstanceState);
        }
    
        private void showPhoto(int photoIndex) {
            ImageView imageView = (ImageView) findViewById(R.id.image_view);
            imageView.setImageResource(mPhotoIds[photoIndex]);
    
            TextView statusText = (TextView) findViewById(R.id.status_text);
            statusText.setText(String.format("%d/%d", photoIndex + 1,
                    mPhotoIds.length));
        }
    }
  • 相关阅读:
    程序报错怎么进入调试
    va01 无定价过程能被确定
    维护销售区域数据
    SAP VA01 消息 没有用于售达方 XXXXXX 的客户主记录存在
    SAP常见问题与解决方法
    客户没有对功能定义,合作伙伴
    SAP名词解释-售达方|送达方
    英语-20210312
    配置预付款-科目对应关系FBKP
    unzip 解压指定的文件夹或文件 到指定的目录
  • 原文地址:https://www.cnblogs.com/onelikeone/p/7586908.html
Copyright © 2011-2022 走看看