ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文
Android : NumberPicker を数字入力では無く『インデックス』として使う
日時: 2015/10/12 01:05
名前: lightbox



拡張子:
<?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>
拡張子:
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);

	}
}
メンテナンス


日時: 2015/10/12 01:05
名前: lightbox