zoukankan      html  css  js  c++  java
  • 安卓学习-界面-ui-NumberPicker

    activity_main.xml

    <RelativeLayout 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"
        tools:context="${relativePackage}.${activityClass}" >
    
        <NumberPicker
            android:id="@+id/numberPicker1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true" />
    
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/numberPicker1"
            android:layout_marginLeft="17dp"
            android:text="数值:"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginTop="18dp"
            android:layout_toRightOf="@+id/textView1"
            android:text="设置成50" />
    
    </RelativeLayout>
    View Code

    MainActivity.java

    public class MainActivity extends Activity {
    
        NumberPicker numberPicker;
        Button button1;
        
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            numberPicker=(NumberPicker)findViewById(R.id.numberPicker1);
            numberPicker.setMaxValue(100);
            numberPicker.setMinValue(1);
            numberPicker.setOnValueChangedListener(new OnValueChangeListener() {
                
                @Override
                public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
                    TextView textView1=(TextView)findViewById(R.id.textView1);
                    textView1.setText("原【"+oldVal+"】"+"改成【"+newVal+"】");
                }
            });
    
            
            button1=(Button)findViewById(R.id.button1);
            button1.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    //这里居然不会触发setOnValueChangedListener,算是bug吗
                    numberPicker.setValue(50);
                    
                }
            });
        }
    }
    View Code
  • 相关阅读:
    上位机获取Mjpeg视频流程序(C#.NET语言+AForge.NET控件)(待测试)
    C# Ping类的使用
    四旋翼上位机模拟显示四轴状态
    利用Sniffer分析 ARP报文
    C# 基于CSGL opengl
    用C#实现对本机IP地址的设置
    使用grub4dos引导Linux
    几个常用的批处理(DOS指令)的应用
    四旋翼飞行器之OSD(基本完成)
    Posix多线程编程学习笔记(转)
  • 原文地址:https://www.cnblogs.com/weijj/p/3968465.html
Copyright © 2011-2022 走看看