D
D
dangerclose2015-12-08 07:16:04
Android
dangerclose, 2015-12-08 07:16:04

Is it possible to assign multiple commands to one Button?

Is it possible to assign multiple commands to one Button? In one activity, for example, so that several types of text are displayed in turn.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Goryachkin, 2015-12-08
@dangerclose

If I understand correctly what you need, then you can of course create an external variable and use it instead of a flag, like this:

private int state = 0;
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        if (state == 0) {
             //показываем первый кусок
             state = 1;
         }
         else if (state == 1) { 
             //показываем второй кусок
             state = 2
          }
          else {
              //тут действие по умолчанию
          }
    }
});

E
Erkin59, 2016-08-22
@Erkin59

I usually use the TAG of the button itself

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question