Mostrando entradas con la etiqueta NumberPicker. Mostrar todas las entradas
Mostrando entradas con la etiqueta NumberPicker. Mostrar todas las entradas

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:


Crud Simple en laravel 8