<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                上回主要做了設置向導界面的界面設計,主要涉及到界面的布局和一些控件的使用。這次要做設置向導界面的功能具體實現。 首先,4個界面分別是(重復度很大,這里就不再貼到正文中了) 1. [/mobilesafe/res/layout/setup_wizard1.xml](https://github.com/hoxis/mobilesafe/blob/master/res/layout/setup_wizard1.xml) 1. [/mobilesafe/res/layout/setup_wizard2.xml](https://github.com/hoxis/mobilesafe/blob/master/res/layout/setup_wizard2.xml) 1. [/mobilesafe/res/layout/setup_wizard3.xml](https://github.com/hoxis/mobilesafe/blob/master/res/layout/setup_wizard3.xml) 1. [/mobilesafe/res/layout/setup_wizard4.xml](https://github.com/hoxis/mobilesafe/blob/master/res/layout/setup_wizard4.xml) ### Activity之間的切換動畫效果 - public void **overridePendingTransition**(int enterAnim, int exitAnim) > 兩個參數: > - **enterAnim**:進入新Activity的動畫效果 > - **exitAnim**:退出當前Activity的動畫效果 ### 創建動畫效果: - /mobilesafe/res/anim/alpha_in.xml ~~~ <?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="300" android:fromAlpha="0.0" android:toAlpha="1.0" > </alpha> ~~~ - [/mobilesafe/res/anim/alpha_out.xml](https://github.com/hoxis/mobilesafe/blob/master/res/anim/alpha_out.xml) ### 為“下一步”按鈕添加點擊事件: - [/mobilesafe/src/com/liuhao/mobilesafe/ui/SetupWizard1Activity.java](https://github.com/hoxis/mobilesafe/blob/master/src/com/liuhao/mobilesafe/ui/SetupWizard1Activity.java) ~~~ package com.liuhao.mobilesafe.ui; import com.liuhao.mobilesafe.R; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class SetupWizard1Activity extends Activity implements OnClickListener { private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.setup_wizard1); button = (Button) this.findViewById(R.id.bt_next); button.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.bt_next: finish();// 用戶點擊“后退”時不會再看到這個界面 Intent intent = new Intent(this, SetupWizard2Activity.class); startActivity(intent); // 設置Activity切換時的動畫效果 overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out); break; } } } ~~~ ### 設置界向導面2 需求功能: 1. 綁定SIM卡 2. CheckBox狀態的處理 3. 上一步、下一步 點擊功能的實現 - **綁定SIM卡** 在用戶點擊“綁定SIM卡”時,觸發相應的處理邏輯,獲取當前SIM卡的串號,并將串號存取到SharePreference中。 要獲取手機SIM卡串號,需要添加權限:**android.permission.READ_PHONE_STATE** ~~~ /** * 綁定SIM串號 * */ private void setSimInfo() { TelephonyManager manager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); String simSerialNumber = manager.getSimSerialNumber(); Editor edit = sp.edit(); edit.putString("sim", simSerialNumber); edit.commit(); Toast.makeText(getApplicationContext(), "SIM卡已綁定", Toast.LENGTH_SHORT).show(); } ~~~ - **CheckBox狀態的處理** ~~~ // 首先初始化chexkbox的狀態 String sim = sp.getString("sim", null); if(sim != null){ cb_bind.setText("已綁定SIM卡"); cb_bind.setChecked(true); }else{ cb_bind.setText("未綁定SIM卡"); cb_bind.setChecked(false); } cb_bind.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(isChecked){ setSimInfo(); cb_bind.setText("已綁定SIM卡"); }else{ cb_bind.setText("未綁定SIM卡"); } } }); ~~~ ### 異常處理 弄好,運行代碼,綁定手機SIM卡串號,沒有問題。 再次打開,進入向導2界面時,出錯,程序崩潰。 ### 錯誤日志(摘取了主要部分) E/AndroidRuntime(26463): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.liuhao.mobilesafe/com.liuhao.mobilesafe.ui.SetupWizard2Activity}: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean ... E/AndroidRuntime(26463): at com.liuhao.mobilesafe.ui.SetupWizard2Activity.onCreate(SetupWizard2Activity.java:42) ### 原因: 由于之前判斷SharePreference中是否存在SIM信息是根據下面的邏輯: ~~~ // 首先初始化chexkbox的狀態 if(sp.getBoolean("sim", false)){ cb_bind.setText("已綁定SIM卡"); cb_bind.setChecked(true); }else{ cb_bind.setText("未綁定SIM卡"); cb_bind.setChecked(false); } ~~~ 而**boolean android.content.SharedPreferences.getBoolean(String key, boolean defValue)**方法, > Retrieve a boolean value from the preferences. > Parameters: key The name of the preference to retrieve. defValue Value to return if this preference does not exist. Returns: Returns the preference value if it exists, or defValue. Throws ClassCastException if there is a preference with this name that is not a boolean. Throws: ClassCastException 可以發現,若已存在值,而這個值不是Boolean類型時將會拋出ClassCastException。 ### 修改 ~~~ // 首先初始化chexkbox的狀態 String sim = sp.getString("sim", null); if(sim != null){ cb_bind.setText("已綁定SIM卡"); cb_bind.setChecked(true); }else{ cb_bind.setText("未綁定SIM卡"); cb_bind.setChecked(false); } ~~~ ### 運行效果 ![](image/d41d8cd98f00b204e9800998ecf8427e.png) ![](image/d41d8cd98f00b204e9800998ecf8427e.png) #### 完整代碼: - [/mobilesafe/src/com/liuhao/mobilesafe/ui/SetupWizard2Activity.java](https://github.com/hoxis/mobilesafe/blob/master/src/com/liuhao/mobilesafe/ui/SetupWizard2Activity.java)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看