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

miércoles, 3 de julio de 2019

DatePicker en android

El DatePicker es importante, para que el usuario final pueda seleccionar de manera fácil una fecha especifica. Esto es importante para una mejor experiencia del usuario. para poder implementar esto en un proyecto debemos codificarlo de la siguiente manera:
Primero el XML:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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">

    
    <Button
        android:id="@+id/btn_datepicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/date"
        android:onClick="onClickDatePicker"/>
    <TextView
        android:id="@+id/texto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/date"
        />
</LinearLayout>
Luego el archivo Java, que seria de la siguiente manera:

package com.example.datepicker;

import android.app.DatePickerDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements DatePickerDialog.OnDateSetListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    public void onClickDatePicker(View view){
        DatePickerDialog date = new DatePickerDialog(this,this,2000,1,1);
        date.show();
    }
    @Override
    public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) {
        TextView texto =(TextView) findViewById(R.id.texto);
        texto.setText(String.format("%1$04d/%2$02d/%3$02d",year,monthOfYear,dayOfMonth));
    }
}
Y el resultado seria el siguiente:



El idioma del calendario, depende de la configuración del celular.

jueves, 27 de junio de 2019

TimePicker en android

Los TimePicker en android son controles(vistas) que nos permiten seleccionar un determinada hora y ponerlo en otro control(vista) o para uso particular. Esto ayuda al usuario final una mejor experiencia al momento de seleccionar la hora. Ahora te mostrare como insertar un control TimePicker paso a paso

Primero el XML:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TimePicker"
        android:onClick="onClickTimePicker"/>
    <TextView
        android:id="@+id/texto"
        android:layout_margin="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Timer Picker"/>
</LinearLayout>

Luego el MainActivity.java


package com.example.numberpicker;
import android.app.TimePickerDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.NumberPicker;
import android.widget.TextView;
import android.widget.TimePicker;
public class MainActivity extends AppCompatActivity implements TimePickerDialog.OnTimeSetListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    @Override
    public void onTimeSet(TimePicker timePicker, int i, int i1) {
        TextView texto=(TextView) findViewById(R.id.texto);
        texto.setText(String.format("%1$02d:%2$02d",i,i1));
    }
    public void onClickTimePicker(View view){
        TimePickerDialog time = new TimePickerDialog(this,this,12,0,true);
        time.show();
    }
}


El resultado final seria el siguiente.



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