How do I make the Android array content output button?

Asked 2 years ago, Updated 2 years ago, 23 views

From Android

I'm going to make it like this.

TextView remains unchanged

TEXT contains "OFF", "1", "2", and "3". If you press ◁ in this state, it goes down to OFF ▷ Press to go up to 3.

If you press ◁ while the contents of the TEXT are OFF, it will no longer go down and will remain OFF Similarly, you want to keep the number 3 on the TEXT even if you press ▷ while the number 3 written on it.

I'm going to put the contents of TEXT in an array like ArrayList or string What should I do?

Please tell me Crying.

android

2022-09-22 13:51

1 Answers

List<String> list = ArrayList<>();
list.add("OFF");
list.add("0");
list.add("1");
list.add("2");
list.add("3");
int currentPosition = 0; //Default

textView.setText(list.get(currentPosition))

//When you click the right button
void rightBtnClick(){
    if(currentPosition == 0) return;
    textView.setText(list.get(--currentPosition));
}

//Click the left button
void leftBtnClick(){
    if(currentPosition == list.size() -1) return;
    textView.setText(list.get(++currentPosition));
}

I think it's going to be like this. I just wrote it, so please refer to the context only in case there are any mistakes.


2022-09-22 13:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.