我想说的话

今天晚上我依然在图书馆写博客,其实此刻我的没心激动而忐忑,因为明天就是足球赛的决赛,我作为主力球员压力很大,因对对方很强大,但是那又怎么样。so what。。。我不会停止写博客的

NumberPicker简介

NumberPicker这个控件可以让你滑动来选择数值。

通过三个方法来设置:

1.setMinValue()

2.setMaxVlaue()

3.setValue()

代码示例

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
        android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        tools:context=".MainActivity"
    android:orientation="vertical"
        >
    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="120dp"
            android:layout_height="wrap_content"
            android:text="选择低价"/>
        <NumberPicker
        android:id="@+id/np1"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:focusable="true"
        android:focusableInTouchMode="true"
        />
</TableRow>
    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="120dp"
            android:layout_height="wrap_content"
            android:text="选择低价"/>
        <NumberPicker
            android:id="@+id/np2"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:focusable="true"
            android:focusableInTouchMode="true"/>
    </TableRow>
</TableLayout>
package peng.liu.test;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CalendarView;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.NumberPicker;
import android.widget.SimpleAdapter;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
import android.widget.ViewFlipper;
import android.widget.ViewSwitcher;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends Activity {
    private NumberPicker np1,np2;
    private int minValue = 25;
    private int maxValue = 75;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        np1 = (NumberPicker) findViewById(R.id.np1);
        np2 = (NumberPicker) findViewById(R.id.np2);
        np1.setMinValue(10);
        np1.setMaxValue(50);
        np1.setValue(minValue);
        np2.setMinValue(50);
        np2.setMaxValue(100);
        np2.setValue(maxValue);
        np1.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
            @Override
            public void onValueChange(NumberPicker numberPicker, int i, int i2) {
                   minValue = i2;
                showNumber();
            }
        });
        np2.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
            @Override
            public void onValueChange(NumberPicker numberPicker, int i, int i2) {
                maxValue = i2;
                showNumber();
            }
        });
    }
    public void showNumber(){
        Toast.makeText(this,minValue+maxValue+"",Toast.LENGTH_LONG).show();
    }
}

效果图

Android的数字选择器NumberPicker-android学习之旅(三十七)的更多相关文章

  1. Android数字选择器-NumberPicker

    数字选择器NumberPicker是Android3.0之后引入的一个控件,比较常用,比如说手机常用的闹钟,可以选择小时和分钟,如果你需要兼容3.0之前版本,GitHub上有开源的项目,具体的下载地址 ...

  2. 开发了5年android,我开始了go学习之旅

    前言 做了近5年的android开发,最近项目也是不怎么忙,空闲的时候总会思考一些事情,不过作为移动开发,我个人觉得很有必要学习后台开发,由于公司是Go语言开发的,了解go语言一段时间后,我发现go语 ...

  3. Android列表视图ListView和ListActivity-android学习之旅(二十四)

    ListView简介 ListView是android中常用的一种控件,创建ListView有两种方式: 1.在xml中使用ListView控件创建. 2.使用activity继承ListActivi ...

  4. Android的ViewAnimator及其子类ViewSwitcher-android学习之旅(三十三)

    ViewAnimator继承了FrameLayout,多个组件重合在一起,可以加入多个组件,然后切换的时候会有动画. ViewAnimator及其子类的继承关系 ViewAnimator常用属性 Vi ...

  5. 滴滴Booster移动APP质量优化框架 学习之旅 三

    推荐阅读: 滴滴Booster移动App质量优化框架-学习之旅 一 Android 模块Api化演练 不一样视角的Glide剖析(一) 滴滴Booster移动App质量优化框架-学习之旅 二对重复资源 ...

  6. Hadoop学习之旅三:MapReduce

    MapReduce编程模型 在Google的一篇重要的论文MapReduce: Simplified Data Processing on Large Clusters中提到,Google公司有大量的 ...

  7. Dynamic CRM 2013学习笔记(三十七)自定义审批流7 - 初始化(整套审批流下载、安装)

    前面介绍了自定义审批流的配置.使用,这篇介绍下如何进行初始化. 一. 下载 从下面的地址下载整个审批流: http://yunpan.cn/cZ5Rdx5HCt3VF 下载完后,一共有三块内容: 二. ...

  8. Android文本框-android学习之旅(十七 )

    文本框简介 文本框属于基本的andoid控件,TextView继承了View是最基本的文本框,它的子类包括EditView和Button等,TextView的大部分方法,它的子类也可以使用. Text ...

  9. struts2学习之旅三 权限管理和导航设计

    1,权限管理的db设计和dao实现,尽量简单快速有效: db的设计如下:权限按照角色来赋给用户: 权限对应每一个具体的功能,有菜单级别的,有导航级别的,还有页面级别的功能: 涉及到权限的敏感操作一般都 ...

随机推荐

  1. Python3 sys.argv[ ]的用法解释

    sys.argv[]说白了就是一个从程序外部获取参数的桥梁,这个"外部"很关键,所以那些试图从代码来说明它作用的解释一直没看明白.因为我们从外部取得的参数可以是多个,所以获得的是一 ...

  2. avalon加载一闪而过现象

      为了避免未经处理的原始模板内容在页面载入时在页面中一闪而过,我们可以使用以下样式(详见这里): .ms-controller,.ms-important,[ms-controller],[ms-i ...

  3. java中JSON转换

    1.JSON介绍 JSON是一种取代XML的数据结构,和xml相比,它更小巧但描述能力却不差,由于它的小巧所以网络传输数据将减少更多流量从而加快速度. JSON就是一串字符串 只不过元素会使用特定的符 ...

  4. SVN冲突解决

    问题一.执行SVN commit时候,会生成除正常文件之外.mine..r3439 ..r3368的三个文件 .mine:是自己要提交的版本 .r3439:在别人之前提交的版本 .r3368:初始版本 ...

  5. Linux的哲学思想

    1.一切皆文件:2.单一目的的小程序:3.组合小程序完成复杂任务:4.文本文件保存配置信息:5.尽量避免捕获用户接口:6.提供机制,而非策略. 说到底Linux的哲学思想在于方便和更好的管理后台,不同 ...

  6. 解决 Popup 位置不随窗口移动更新的问题

    Popup弹出后,因业务需求设置了StaysOpen=true后,移动窗口位置或者改变窗口大小,Popup的位置不会更新. 如何更新位置? 获取当前Popup的Target绑定UserControl所 ...

  7. JavaScript正则表达式模式匹配(3)——贪婪模式和惰性模式

    var pattern=/[a-z]+/; //这里使用了贪婪模式, var str='abcdefg'; alert(str.replace(pattern,'1')); //所有的字符串变成了1 ...

  8. 匿名函数lambda

    匿名函数的定义 在python中,匿名函数的定义如下: func =lambda x:x+1 #定义匿名函数,x为传参,x+1为返回值,func为函数名 res = func(10) #执行匿名函数 ...

  9. Mac下安装PEAR

    The following instructions install PEAR and PECL on Mac OS X under/usr/local/. PECL is bundled with ...

  10. Node.js Net 模块

    Node.js Net 模块提供了一些用于底层的网络通信的小工具,包含了创建服务器/客户端的方法,我们可以通过以下方式引入该模块: var net = require("net") ...