@DIV
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<NumberPicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/numberPicker"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"/>
</RelativeLayout>
@END
@DIV
package sample.lightbox.test1008;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.NumberPicker;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NumberPicker np = (NumberPicker) findViewById(R.id.numberPicker);
String[] nums = new String[3];
nums[0] = "赤";
nums[1] = "青";
nums[2] = "黄";
int[] values = new int[3];
values[0] = -10;
values[1] = 20;
values[2] = 100;
np.setMinValue(0);
np.setMaxValue(2);
np.setDisplayedValues(nums);
np.setValue(1);
}
}
@END |