activity_main.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="ir.mhdr.a070.MainActivity"> <NumberPicker android:id="@+id/numberPicker2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="166dp" /> </RelativeLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity { NumberPicker numberPicker; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); numberPicker= (NumberPicker) findViewById(R.id.numberPicker2); numberPicker.setMaxValue(99); numberPicker.setMinValue(0); numberPicker.setValue(25); numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); } }
References
https://github.com/mhdr/AndroidSamples/tree/master/070