简体   繁体   中英

How to save button click state in order in android. (Not Toggle Button)

Im new to android and I have one problem that bothers me.

I have multiple buttons like the image below https://lh4.ggpht.com/ouHPcTcFzsdYrTU09pStGBicxgX_cki613g5Eq3loYCh2TOXzqpfeyWnOdlLuc8eNS0=h900-rw

1.what I want to do is to press 5 buttons in any order.
2.Save the clicked buttons text in order of the clicks.

For Example. I have 1 ~ 31 buttons, and if I press five numbers 1,5,7,8,2
The 5 Buttons that have been clicked will be saved in clicked order.

3.Should I use SharedPreference and ArrayList? I dont want to use toggle button and check box but a simple Button. I'm not sure what kind logic and class I must use. I'm a noob so if possible, a sample will help me learn a lot !

Try to use

clickedButtons = new ArrayList<View>();
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!v.isSelected()) {
                v.setSelected(true);
                clickedButtons.add(v);
            }
        }
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM