最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

簡(jiǎn)介:

NumberPicker: 用戶(hù)既可以從鍵盤(pán)輸值,也可以拖動(dòng)來(lái)選擇值

實(shí)際效果:

常用方法:

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

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

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

在布局文件中調(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="選擇時(shí)鐘"
      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)聽(tīng)事件:

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

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

具體實(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è)置哪怕的當(dāng)前值
    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è)置哪怕的當(dāng)前值
    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è)定鬧鐘時(shí)間為:" + min + " : " + max,Toast.LENGTH_SHORT).show();
  }
}

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

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

相關(guān)文章

最新評(píng)論

天长市| 清苑县| 阆中市| 新安县| 合阳县| 河津市| 阿荣旗| 安平县| 铜山县| 滕州市| 监利县| 仙游县| 乡宁县| 巍山| 绥化市| 望都县| 甘肃省| 黔江区| 崇左市| 安徽省| 门头沟区| 彰化县| 平南县| 方山县| 施甸县| 准格尔旗| 曲水县| 泰兴市| 玉屏| 资阳市| 黔南| 马鞍山市| 泾源县| 安溪县| 南岸区| 漠河县| 广南县| 巴里| 安康市| 宁安市| 济南市|