簡體   English   中英

我想制作沒有對話框的數字選擇器

[英]I want to make number picker without dialog android

<NumberPicker
    android:id="@+id/firstSeekBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:background="@drawable/image3" />

我如何獲得數字選擇器的值並像TimePickerDialog一樣移動

這是我用於日期和時間的號碼選擇器:

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.NumberPicker;

@TargetApi(Build.VERSION_CODES.HONEYCOMB)//For backward-compability
public class NumberPickerMinMax extends NumberPicker
{
    public NumberPickerMinMax(Context context) 
    {
        super(context);
    }

    public NumberPickerMinMax(Context context, AttributeSet attrs) 
    {
        super(context, attrs);
        processAttributeSet(attrs);
    }

    public NumberPickerMinMax(Context context, AttributeSet attrs, int defStyle) 
    {
        super(context, attrs, defStyle);
        processAttributeSet(attrs);
    }

    private void processAttributeSet(AttributeSet attrs) 
    {
        //This method reads the parameters given in the xml file and sets the properties according to it
        this.setMinValue(attrs.getAttributeIntValue(null, "min", 0));
        this.setMaxValue(attrs.getAttributeIntValue(null, "max", 0));
    }
}

現在您需要為每個時間位數添加4 NumberPickerMinMax :HH:mm,這是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" >

        <com.evapp.customViews.NumberPickerMinMax
            android:id="@+id/TimePickerView_hour2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="2dp"
            min="0"
            max="9"
            android:layout_toLeftOf="@+id/textView1" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text=" - "
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <com.evapp.customViews.NumberPickerMinMax
            android:id="@+id/TimePickerView_hour1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_margin="2dp"
            min="0"
            max="2"
            android:layout_toLeftOf="@+id/TimePickerView_hour2" />

        <com.evapp.customViews.NumberPickerMinMax
            android:id="@+id/TimePickerView_minutes1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="2dp"
            min="0"
            max="5"
            android:layout_toRightOf="@+id/textView1" />

        <com.evapp.customViews.NumberPickerMinMax
            android:id="@+id/TimePickerView_minutes2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="2dp"
            min="0"
            max="9"
            android:layout_toRightOf="@+id/TimePickerView_minutes1" />

    </RelativeLayout>

</RelativeLayout> 

希望這就是你所需要的

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM