Number picker only allowing zero as value

933 views Asked by At

I am making an app that utilizes the numberpicker. What happens is when I try to create the numberpicker and set its attributes, it just simply won't do anything. The only value it allows is zero, and you can't scroll the numbers with it either. After a lot of google searches, I'm quite certain that I put the min/max-value methods in the right order.

I would appreciate some guidance of what I'm doing wrong.

source:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.NumberPicker;

public class Start extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);

        NumberPicker minutePicker = (NumberPicker) findViewById(R.id.minutePicker);
        minutePicker.setMaxValue(100);
        minutePicker.setMinValue(0);
        minutePicker.setWrapSelectorWheel(false);

        NumberPicker secondPicker = (NumberPicker) findViewById(R.id.secondPicker);
        secondPicker.setMaxValue(60);
        secondPicker.setMinValue(0);
        secondPicker.setWrapSelectorWheel(false);



    }
}

edit: Added XML file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/twoPickers"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.listifymusic.listifymusic.Start">

    <NumberPicker
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="45dp"
        android:layout_marginStart="45dp"
        android:id="@+id/secondPicker"
        android:layout_alignBaseline="@+id/minutePicker"
        android:layout_alignBottom="@+id/minutePicker"
        android:layout_toRightOf="@+id/minutePicker"
        android:layout_toEndOf="@+id/minutePicker" />

    <NumberPicker
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/minutePicker"
        android:layout_marginLeft="102dp"
        android:layout_marginStart="102dp"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>
2

There are 2 answers

0
Distwo On BEST ANSWER

Make sure your activity is set as launcher activity in your manifest.xml:

<activity android:name=".Start">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>

        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>
0
OneCricketeer On

You've started some other Activity that is essentially doing only this.

public class SomeOtherActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);
    }
}

In other words, the code you have should work if you start the Start activity.