miércoles, 26 de junio de 2019

NumberPicker en Android

En android se puede usar el NumberPicker para seleccionar numero en un rango establecido mediante codigo fuente. Su utilidad son diversas, aqui te mostramos como utilizarlos en tus proyectos.

Primero codificamos el XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical">
    <NumberPicker
        android:id="@+id/numberpicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"></NumberPicker>
    <TextView
        android:id="@+id/texto"
        android:layout_margin="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Number Picker"
        android:layout_toRightOf="@id/numberpicker" />
</RelativeLayout>
Y el archivo java seria: MainActivity.java
package com.example.numberpicker;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.NumberPicker;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
    private NumberPicker numberPicker;
    private TextView texto;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        texto=(TextView)findViewById(R.id.texto);
        numberPicker=(NumberPicker)findViewById(R.id.numberpicker);
        numberPicker.setMinValue(1);
        numberPicker.setMaxValue(31);
        numberPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
            @Override
            public void onValueChange(NumberPicker numberPicker, int i, int i1) {
                texto.setText("Valor anterior: "+i+" Valor Nuevo: "+i1);
            }
        });
    }
}

Y el resultado seria el siguiente:


1 comentario:

  1. Gambling at Wynn - Dr. Md.
    › wiki › Gambling_at_wynn_ › wiki 경기도 출장샵 › Gambling_at_wynn_ Gambling at Wynn. The casino is a 3-story, 4-star 당진 출장안마 hotel 양주 출장마사지 with two restaurants and an outdoor 안동 출장샵 pool. The casino's 아산 출장마사지 1596 room-scale gaming space

    ResponderEliminar

Crud Simple en laravel 8