brucetoo/PickView

Adding Picker To View

Closed this issue · 6 comments

Can I add the picker to a View instead of using it as a popup?

Of course,you can see popup code how to use picker.

I mean adding it as a child view to a Layout(Relative, Frame, Linear etc...)

Why not?

Okay. Can you help out? Or tell me what to do?

I tried to implement it and I get a Laggy LoopView and the Section meant to display selected value, is Opaque. This is what I did

 <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:layout_marginBottom="16dp">

            <com.bruce.pickerview.LoopView
                android:id="@+id/pick_date"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1.3" />

            <com.bruce.pickerview.LoopView
                android:id="@+id/pick_hour"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginLeft="1dp"
                android:layout_marginStart="1dp"
                android:layout_weight="1" />

            <com.bruce.pickerview.LoopView
                android:id="@+id/pick_minute"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginLeft="1dp"
                android:layout_marginStart="1dp"
                android:layout_weight="1" />
        </LinearLayout>

And in code:

  private void getnerateHour() {
    hourLoopView.setNotLoop();
    hourLoopView.setTextSize(20);
    minuteLoopView.setNotLoop();
    minuteLoopView.setTextSize(20);
    int hourCount = 24;
    int minuteCount = 60;

    for (int i = 0; i < hourCount; i++) {
        minuteList.add(String.valueOf(i));
    }

    for (int j = 0; j < minuteCount; j++) {
        hourList.add(String.valueOf(j));
    }

    minuteLoopView.setArrayList((ArrayList) minuteList);
    minuteLoopView.setInitPosition(0);

    hourLoopView.setArrayList((ArrayList) hourList);
    hourLoopView.setInitPosition(0);
}

private void generateDate() {
    dateLoopView.setNotLoop();
    dateLoopView.setTextSize(20);
    Date date = new Date();
    DateTimeZone defaultZone = DateTimeZone.getDefault();
    DateTime now = new DateTime(date, defaultZone);

    for (int i = 0; i < 8; i++) {
        DateTime current = now.plusDays(i);
        if (current == now) {
            dateList.add("Today");
        } else {
            dateList.add(current.dayOfWeek().getAsShortText() + " " + current.dayOfMonth().getAsShortText() + " " + current.monthOfYear().getAsShortText());
        }
    }
    dateLoopView.setArrayList((ArrayList) dateList);
    dateLoopView.setInitPosition(0);
}

please try version 1.2.0