타임피커의 스피너처럼 돌아가는 회전형 커스텀 메뉴를 만들고싶었다.
넘버피커를 활용하면 될거같은데?라고 막연히 생각하던중
딱맞는걸 찾았다 대박적
출처는 여기
https://stackoverflow.com/questions/33163828/ios-like-spinner
1. 일단 xml에서 넘버피커 하나 만들어주기
<NumberPicker
android:id="@+id/numberpicker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:selectionDividerHeight="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
아래 부분은 디바이더가 꼴보기싫어서 없앤것.. 보기싫어..
android:selectionDividerHeight="0dp"
2. 해당 액티비티에서 마저 작성하기
NumberPicker numberpicker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sound_set);
numberpicker = (NumberPicker) findViewById(R.id.numberpicker);
//Initializing a new string array with elements
final String[] values= {"아이템 1","아이템 2", "아이템 3"};
//Populate NumberPicker values from String array values
//Set the minimum value of NumberPicker
numberpicker.setMinValue(0); //from array first value
//Specify the maximum value/number of NumberPicker
numberpicker.setMaxValue(values.length-1); //to array last value
//Specify the NumberPicker data source as array elements
numberpicker.setDisplayedValues(values);
//Gets whether the selector wheel wraps when reaching the min/max value.
numberpicker.setWrapSelectorWheel(true);
//Set a value change listener for NumberPicker
numberpicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal){
//Display the newly selected value from picker
Toast.makeText(getApplicationContext(), "Selected value : " + values[newVal], Toast.LENGTH_SHORT).show();
}
});
}
이러면 됨~!
'android' 카테고리의 다른 글
NumberPicker 커스텀하기(색상바꾸기, 글자크기 키우기, 구분선 지우기) (1) | 2021.12.01 |
---|---|
[TimePicker] 타임피커 스피너타입 색상변경하기 (0) | 2021.11.30 |
[안드로이드][카카오맵] 지도 미 표시 문제(aka. 릴리즈키&디버그키 해시확인) (1) | 2021.07.02 |
안드로이드에서 다음(카카오) 지도 검은 화면으로 나올 때 (0) | 2021.03.19 |
녹스에서 로컬서버 연결하기 (0) | 2021.03.16 |