I posted a spinner question last time, and now I know why the spinner doesn't move, but I still don't know how to do it.
To explain again, the app concept is an app that sets the time to remind you of what you have to do repeatedly, and when you press the button, notification comes in time.
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pickTime();
}
});
public void pickTime() {
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(position == 1) {
System.out.println(position);
setClock1();
} } else if(position == 2) {
System.out.println(position);
setClock2();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
If you do the run and press the button, there is no action or error. If you change the spinner to a different value, it moves without pressing the button.
I heard that the spinner's listener is registered only when the button is pressed, so please advise how to make it work after the execution.
android spinner
If you wrote the code on Activity
Register a spinner listener on Create.
And whenever I choose a spinner item,
Save the selected item in the variable.
If you press button, check the value stored in the variable and call the setClock function.
© 2024 OneMinuteCode. All rights reserved.