pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <tfoot id='v2Qeg'></tfoot>
    • <bdo id='v2Qeg'></bdo><ul id='v2Qeg'></ul>

    <small id='v2Qeg'></small><noframes id='v2Qeg'>

        <legend id='v2Qeg'><style id='v2Qeg'><dir id='v2Qeg'><q id='v2Qeg'></q></dir></style></legend>
      1. <i id='v2Qeg'><tr id='v2Qeg'><dt id='v2Qeg'><q id='v2Qeg'><span id='v2Qeg'><b id='v2Qeg'><form id='v2Qeg'><ins id='v2Qeg'></ins><ul id='v2Qeg'></ul><sub id='v2Qeg'></sub></form><legend id='v2Qeg'></legend><bdo id='v2Qeg'><pre id='v2Qeg'><center id='v2Qeg'></center></pre></bdo></b><th id='v2Qeg'></th></span></q></dt></tr></i><div class="lpvrt7f" id='v2Qeg'><tfoot id='v2Qeg'></tfoot><dl id='v2Qeg'><fieldset id='v2Qeg'></fieldset></dl></div>

        帶有數字選擇器的 Android PreferenceActivity 對話框

        Android PreferenceActivity dialog with number picker(帶有數字選擇器的 Android PreferenceActivity 對話框)

          <i id='L9MXa'><tr id='L9MXa'><dt id='L9MXa'><q id='L9MXa'><span id='L9MXa'><b id='L9MXa'><form id='L9MXa'><ins id='L9MXa'></ins><ul id='L9MXa'></ul><sub id='L9MXa'></sub></form><legend id='L9MXa'></legend><bdo id='L9MXa'><pre id='L9MXa'><center id='L9MXa'></center></pre></bdo></b><th id='L9MXa'></th></span></q></dt></tr></i><div class="tnp7xfh" id='L9MXa'><tfoot id='L9MXa'></tfoot><dl id='L9MXa'><fieldset id='L9MXa'></fieldset></dl></div>

          1. <tfoot id='L9MXa'></tfoot>
              <tbody id='L9MXa'></tbody>
            <legend id='L9MXa'><style id='L9MXa'><dir id='L9MXa'><q id='L9MXa'></q></dir></style></legend>

                <small id='L9MXa'></small><noframes id='L9MXa'>

                • <bdo id='L9MXa'></bdo><ul id='L9MXa'></ul>
                  本文介紹了帶有數字選擇器的 Android PreferenceActivity 對話框的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我已經看到了許多針對這個問題的定制解決方案和答案.我需要一些非常簡單的東西,我有一個偏好活動,我所需要的只是其中一個選項將打開帶有數字選擇器的對話框并保存結果.你能指導我一步一步地完成這個嗎?

                  I have seen many customized solutions and answers to this question. I need something very simple, I have a preference activity and all I need is that one of the options will open dialog with a number picker and save the results. Can you please guide me step by step with how to accomplish this?

                  public class SettingsActivity extends PreferenceActivity
                  {
                      @Override
                      protected void onCreate(final Bundle savedInstanceState)
                      {
                          super.onCreate(savedInstanceState);
                          getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();
                          //requestWindowFeature(Window.FEATURE_NO_TITLE);    
                      }
                  
                      public static class MyPreferenceFragment extends PreferenceFragment
                      {
                          @Override
                          public void onCreate(final Bundle savedInstanceState)
                          {
                              super.onCreate(savedInstanceState);
                              addPreferencesFromResource(R.xml.prefs);
                  
                          }
                      }
                  
                  }
                  

                  XML:

                      <SwitchPreference
                          android:key="cross"
                          android:summaryOff="Cross is invisible"
                          android:summaryOn="Cross is visible"
                          android:switchTextOff="OFF"
                          android:switchTextOn="ON"
                          android:title="Cross" 
                          android:defaultValue="true"/>
                  
                      <SwitchPreference
                          android:key="autoP"
                          android:summaryOff="App will go to sleep"
                          android:summaryOn="App will not go to sleep"
                          android:switchTextOff="OFF"
                          android:switchTextOn="ON"
                          android:title="Always On" 
                          android:defaultValue="true"/>
                  
                      <SwitchPreference
                          android:key="tempD"
                          android:summaryOff="Temprature not displayed"
                          android:summaryOn="Temprature displayed"
                          android:switchTextOff="OFF"
                          android:switchTextOn="ON"
                          android:title="Tempature Display" 
                          android:defaultValue="true"/>
                  
                      <ListPreference
                          android:entries="@array/units"
                          android:entryValues="@array/lunits"
                          android:key="listUnits"
                          android:summary="Units schosssing"
                          android:title="Units" android:defaultValue="C"/>
                  
                       <!--Need to add button to open dialog-->       
                  
                  </PreferenceScreen>
                  

                  數字選擇器 XML:

                  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                      android:layout_width="fill_parent"
                      android:layout_height="fill_parent" >
                  
                      <NumberPicker
                          android:id="@+id/numberPicker1"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_alignParentTop="true"
                          android:layout_centerHorizontal="true"
                          android:layout_marginTop="64dp" />
                  
                      <Button
                          android:id="@+id/button2"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_below="@+id/numberPicker1"
                          android:layout_marginLeft="20dp"
                          android:layout_marginTop="98dp"
                          android:layout_toRightOf="@+id/numberPicker1"
                          android:text="Cancel" />
                  
                      <Button
                          android:id="@+id/button1"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_alignBaseline="@+id/button2"
                          android:layout_alignBottom="@+id/button2"
                          android:layout_marginRight="16dp"
                          android:layout_toLeftOf="@+id/numberPicker1"
                          android:text="Set" />
                  
                  </RelativeLayout>
                  

                  推薦答案

                  子類 DialogPreference 來構建您自己的 NumberPickerPreference.

                  Subclass DialogPreference to build your own NumberPickerPreference.

                  我在下面為您實現了一個.它工作得很好,但功能不完整.例如,最小值和最大值是硬編碼的常量.這些實際上應該是首選項 xml 聲明中的屬性.要讓它工作,您需要添加一個 attrs.xml 文件來指定您的自定義屬性.

                  I have implemented one below for you. It works perfectly fine, but is not feature complete. For example the minimum and maximum values are hard-coded constants. These should really be attributes on the preference xml declaration. To get that to work you would need to add an attrs.xml file specifying your custom attributes.

                  有關在庫項目中支持自定義 xml 屬性的 NumberPicker 首選項小部件的完整實現以及展示如何使用它的演示應用,請參閱 GitHub:https://github.com/Alobar/AndroidPreferenceTest

                  For the full implementation of the NumberPicker preference widget that supports custom xml attributes in a library project and a demo app showing how to use it, see GitHub: https://github.com/Alobar/AndroidPreferenceTest

                  您可以將該小部件用作任何其他首選項小部件,除非您必須完全限定名稱:

                  You would use the widget as any other preference widget, except you have to fully qualify the name:

                  preferences.xml

                  <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
                  
                      <com.example.preference.NumberPickerPreference
                          android:key="key_number"
                          android:title="Give me a number"
                          android:defaultValue="55" />
                  
                  </PreferenceScreen>
                  

                  NumberPickerPreference.java

                  package com.example.preference;
                  
                  import android.content.Context;
                  import android.content.res.TypedArray;
                  import android.preference.DialogPreference;
                  import android.util.AttributeSet;
                  import android.view.Gravity;
                  import android.view.View;
                  import android.view.ViewGroup;
                  import android.widget.FrameLayout;
                  import android.widget.NumberPicker;
                  
                  /**
                   * A {@link android.preference.Preference} that displays a number picker as a dialog.
                   */
                  public class NumberPickerPreference extends DialogPreference {
                  
                      // allowed range
                      public static final int MAX_VALUE = 100;
                      public static final int MIN_VALUE = 0;
                      // enable or disable the 'circular behavior'
                      public static final boolean WRAP_SELECTOR_WHEEL = true; 
                  
                      private NumberPicker picker;
                      private int value;
                  
                      public NumberPickerPreference(Context context, AttributeSet attrs) {
                          super(context, attrs);
                      }
                  
                      public NumberPickerPreference(Context context, AttributeSet attrs, int defStyleAttr) {
                          super(context, attrs, defStyleAttr);
                      }
                  
                      @Override
                      protected View onCreateDialogView() {
                          FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
                                  ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                          layoutParams.gravity = Gravity.CENTER;
                  
                          picker = new NumberPicker(getContext());
                          picker.setLayoutParams(layoutParams);
                  
                          FrameLayout dialogView = new FrameLayout(getContext());
                          dialogView.addView(picker);
                  
                          return dialogView;
                      }
                  
                      @Override
                      protected void onBindDialogView(View view) {
                          super.onBindDialogView(view);
                          picker.setMinValue(MIN_VALUE);
                          picker.setMaxValue(MAX_VALUE);
                          picker.setWrapSelectorWheel(WRAP_SELECTOR_WHEEL);
                          picker.setValue(getValue());
                      }
                  
                      @Override
                      protected void onDialogClosed(boolean positiveResult) {
                          if (positiveResult) {
                              picker.clearFocus();
                              int newValue = picker.getValue();
                              if (callChangeListener(newValue)) {
                                  setValue(newValue);
                              }
                          }
                      }
                  
                      @Override
                      protected Object onGetDefaultValue(TypedArray a, int index) {
                          return a.getInt(index, MIN_VALUE);
                      }
                  
                      @Override
                      protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue) {
                          setValue(restorePersistedValue ? getPersistedInt(MIN_VALUE) : (Integer) defaultValue);
                      }
                  
                      public void setValue(int value) {
                          this.value = value;
                          persistInt(this.value);
                      }
                  
                      public int getValue() {
                          return this.value;
                      }
                  }
                  

                  這篇關于帶有數字選擇器的 Android PreferenceActivity 對話框的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Get user#39;s current location using GPS(使用 GPS 獲取用戶的當前位置)
                  IllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 拋出的 IllegalArgumentException)
                  How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?)
                  How to detect Location Provider ? GPS or Network Provider(如何檢測位置提供者?GPS 或網絡提供商)
                  Get current location during app launch(在應用啟動期間獲取當前位置)
                  locationManager.getLastKnownLocation() return null(locationManager.getLastKnownLocation() 返回 null)
                • <i id='DLCyt'><tr id='DLCyt'><dt id='DLCyt'><q id='DLCyt'><span id='DLCyt'><b id='DLCyt'><form id='DLCyt'><ins id='DLCyt'></ins><ul id='DLCyt'></ul><sub id='DLCyt'></sub></form><legend id='DLCyt'></legend><bdo id='DLCyt'><pre id='DLCyt'><center id='DLCyt'></center></pre></bdo></b><th id='DLCyt'></th></span></q></dt></tr></i><div class="jlrxrpz" id='DLCyt'><tfoot id='DLCyt'></tfoot><dl id='DLCyt'><fieldset id='DLCyt'></fieldset></dl></div>
                    <tbody id='DLCyt'></tbody>

                      <small id='DLCyt'></small><noframes id='DLCyt'>

                          <bdo id='DLCyt'></bdo><ul id='DLCyt'></ul>
                          1. <legend id='DLCyt'><style id='DLCyt'><dir id='DLCyt'><q id='DLCyt'></q></dir></style></legend>
                          2. <tfoot id='DLCyt'></tfoot>
                          3. 主站蜘蛛池模板: 实战IT培训机构_IT培训班选大学生IT技术培训中心_中公优就业 | 小型高低温循环试验箱-可程式高低温湿热交变试验箱-东莞市拓德环境测试设备有限公司 | 120kv/2mA直流高压发生器-60kv/2mA-30kva/50kv工频耐压试验装置-旭明电工 | 海水晶,海水素,海水晶价格-潍坊滨海经济开发区强隆海水晶厂 | 春腾云财 - 为企业提供专业财税咨询、代理记账服务 | LED显示屏_LED屏方案设计精准报价专业安装丨四川诺显科技 | 千斤顶,液压千斤顶-力良企业,专业的液压千斤顶制造商,shliliang.com | 煤机配件厂家_刮板机配件_链轮轴组_河南双志机械设备有限公司 | 高楼航空障碍灯厂家哪家好_航空障碍灯厂家_广州北斗星障碍灯有限公司 | 深圳货架厂_仓库货架公司_重型仓储货架_线棒货架批发-深圳市诺普泰仓储设备有限公司 | 保镖公司-私人保镖-深圳保镖公司【环宇兄弟保镖】 | STRO|DTRO-STRO反渗透膜(科普)_碟滤| 深圳VI设计-画册设计-LOGO设计-包装设计-品牌策划公司-[智睿画册设计公司] | 牛皮纸|牛卡纸|进口牛皮纸|食品级牛皮纸|牛皮纸厂家-伽立实业 | 拉力测试机|材料拉伸试验机|电子拉力机价格|万能试验机厂家|苏州皖仪实验仪器有限公司 | 浙江浩盛阀门有限公司 | 武汉高低温试验机-现货恒温恒湿试验箱-高低温湿热交变箱价格-湖北高天试验设备 | 电缆接头_防水接头_电缆防水接头 - 乐清市新豪电气有限公司 | 除湿机|工业除湿机|抽湿器|大型地下室车间仓库吊顶防爆除湿机|抽湿烘干房|新风除湿机|调温/降温除湿机|恒温恒湿机|加湿机-杭州川田电器有限公司 | 泰国专线_泰国物流专线_广州到泰国物流公司-泰廊曼国际 | 北京翻译公司_同传翻译_字幕翻译_合同翻译_英语陪同翻译_影视翻译_翻译盖章-译铭信息 | 送料机_高速冲床送料机_NC伺服滚轮送料机厂家-东莞市久谐自动化设备有限公司 | 品牌设计_VI设计_电影海报设计_包装设计_LOGO设计-Bacross新越品牌顾问 | 太空舱_民宿太空舱厂家_移动房屋太空舱价格-豪品建筑 | 求是网 - 思想建党 理论强党| 屏蔽服(500kv-超高压-特高压-电磁)-徐吉电气| 杭州中央空调维修_冷却塔/新风机柜/热水器/锅炉除垢清洗_除垢剂_风机盘管_冷凝器清洗-杭州亿诺能源有限公司 | 生产自动包装秤_颗粒包装秤_肥料包装秤等包装机械-郑州鑫晟重工科技有限公司 | 环球电气之家-中国专业电气电子产品行业服务网站! | 干洗加盟网-洗衣店品牌排行-干洗设备价格-干洗连锁加盟指南 | 冷凝锅炉_燃气锅炉_工业燃气锅炉改造厂家-北京科诺锅炉 | 杜康白酒加盟_杜康酒代理_杜康酒招商加盟官网_杜康酒厂加盟总代理—杜康酒神全国运营中心 | 电动葫芦-河北悍象起重机械有限公司| 商用绞肉机-熟肉切片机-冻肉切丁机-猪肉开条机 - 广州市正盈机械设备有限公司 | 山东钢衬塑罐_管道_反应釜厂家-淄博富邦滚塑防腐设备科技有限公司 | 东莞螺杆空压机_永磁变频空压机_节能空压机_空压机工厂批发_深圳螺杆空压机_广州螺杆空压机_东莞空压机_空压机批发_东莞空压机工厂批发_东莞市文颖设备科技有限公司 | 奶茶加盟,奶茶加盟店连锁品牌-甜啦啦官网| 除甲醛公司-甲醛检测治理-杭州创绿家环保科技有限公司-室内空气净化十大品牌 | 土壤养分检测仪_肥料养分检测仪_土壤水分检测仪-山东莱恩德仪器 大型多片锯,圆木多片锯,方木多片锯,板材多片锯-祥富机械有限公司 | 中空玻璃生产线,玻璃加工设备,全自动封胶线,铝条折弯机,双组份打胶机,丁基胶/卧式/立式全自动涂布机,玻璃设备-山东昌盛数控设备有限公司 | 环氧铁红防锈漆_环氧漆_无溶剂环氧涂料_环氧防腐漆-华川涂料 |