欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android開發(fā)之滑動數(shù)值選擇器NumberPicker用法示例

 更新時間:2019年03月18日 11:23:56   作者:水中魚之1999  
這篇文章主要介紹了Android開發(fā)之滑動數(shù)值選擇器NumberPicker用法,結(jié)合實例形式分析了Android滑動數(shù)值選擇器NumberPicker的功能、相關(guān)函數(shù)、事件監(jiān)聽、界面布局等操作技巧,需要的朋友可以參考下

本文實例講述了Android開發(fā)之滑動數(shù)值選擇器NumberPicker用法。分享給大家供大家參考,具體如下:

簡介:

NumberPicker: 用戶既可以從鍵盤輸值,也可以拖動來選擇值

實際效果:

常用方法:

1. setMinValue() 設(shè)置組件支持的最小值

2. setMaxValue() 設(shè)置組建支持的最大值

3. setValue() 設(shè)置該組件的當前值

在布局文件中調(diào)用:

<?xml version="1.0" encoding="utf-8" ?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">
  <TableRow
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="vertical">
    <TextView
      android:text="選擇時鐘"
      android:textSize="20dp"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"/>
    <NumberPicker
      android:id="@+id/np1"
      android:solidColor="@color/colorPrimaryDark"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:focusable="true"
      android:focusableInTouchMode="true"/>
  </TableRow>
  <TableRow
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="vertical">
    <TextView
      android:text="選擇分鐘"
      android:textSize="20dp"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"/>
    <NumberPicker
      android:id="@+id/np2"
      android:solidColor="@color/colorAccent"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:focusable="true"
      android:focusableInTouchMode="true" />
  </TableRow>
</TableLayout>

關(guān)于監(jiān)聽事件:

1. setOnValueChangedListener 調(diào)用監(jiān)聽事件

2. onValueChange 具體執(zhí)行( int oldVal :之前詳實的數(shù)值 , int newVal 改變或現(xiàn)時的數(shù)值)

具體實現(xiàn)方法:

public class MainActivity extends Activity {
  private NumberPicker np1,np2;
  //定義上下限具體值
  private int min = 10,max = 50;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    np1 = (NumberPicker) findViewById(R.id.np1);
    //設(shè)置np1的最大值只和最小值
    np1.setMinValue(0);
    np1.setMaxValue(23);
    //設(shè)置哪怕的當前值
    np1.setValue(min);
    np1.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
      @Override
      public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
        min = newVal;
        showSelectedPrice();
      }
    });
    np2 = (NumberPicker) findViewById(R.id.np2);
    //設(shè)置np1的最大值只和最小值
    np2.setMinValue(0);
    np2.setMaxValue(23);
    //設(shè)置哪怕的當前值
    np2.setValue(max);
    np2.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
      @Override
      public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
        min = newVal;
        showSelectedPrice();
      }
    });
  }
  private void showSelectedPrice(){
    Toast.makeText(MainActivity.this,"設(shè)定鬧鐘時間為:" + min + " : " + max,Toast.LENGTH_SHORT).show();
  }
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對大家Android程序設(shè)計有所幫助。

相關(guān)文章

  • Android Parcelable接口使用方法詳解

    Android Parcelable接口使用方法詳解

    這篇文章主要介紹了 Android Parcelable接口使用方法詳解的相關(guān)資料,實現(xiàn)Parcelable就是為了進行序列化,需要的朋友可以參考下
    2017-08-08
  • Android 實現(xiàn)視頻字幕Subtitle和橫豎屏切換示例

    Android 實現(xiàn)視頻字幕Subtitle和橫豎屏切換示例

    下面小編就為大家分享一篇Android 實現(xiàn)視頻字幕Subtitle和橫豎屏切換示例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • Android發(fā)送短信功能代碼

    Android發(fā)送短信功能代碼

    這篇文章主要介紹了Android發(fā)送短信功能代碼,并附有較為詳盡的代碼說明,有助于讀者更好的理解代碼功能,需要的朋友可以參考下
    2014-09-09
  • Android使用MediaRecorder實現(xiàn)錄音及播放

    Android使用MediaRecorder實現(xiàn)錄音及播放

    這篇文章主要為大家詳細介紹了Android使用MediaRecorder實現(xiàn)錄音及播放,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • Android如何實現(xiàn)URL轉(zhuǎn)換成二維碼

    Android如何實現(xiàn)URL轉(zhuǎn)換成二維碼

    這篇文章主要為大家詳細介紹了Android實現(xiàn)URL轉(zhuǎn)換成二維碼的方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • Android實現(xiàn)app分享文件到微信功能

    Android實現(xiàn)app分享文件到微信功能

    這篇文章主要為大家詳細介紹了Android實現(xiàn)app分享文件到微信功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-05-05
  • Android GestureDetector手勢滑動使用實例講解

    Android GestureDetector手勢滑動使用實例講解

    這篇文章主要為大家詳細介紹了Android GestureDetector手勢滑動使用實例,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-07-07
  • Android?Room數(shù)據(jù)庫加密詳解

    Android?Room數(shù)據(jù)庫加密詳解

    這篇文章主要為大家詳細介紹了Android?Room數(shù)據(jù)庫加密,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • Android ReboundScrollView仿IOS拖拽回彈效果

    Android ReboundScrollView仿IOS拖拽回彈效果

    這篇文章主要為大家詳細介紹了Android ReboundScrollView仿IOS拖拽回彈效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • 福利來了!帶你“愛上Android”

    福利來了!帶你“愛上Android”

    送書!一言不合就送書,《愛上Android》一書深入淺出,詳細講解了Android開發(fā)的知識,帶著大家愛上Android,帶領(lǐng)大家開啟真正的Android開發(fā)之旅
    2017-08-08

最新評論