Skip to content Skip to sidebar Skip to footer

Equivalent Of Set= And GetActionCommand In Android Java?

I've just started learning Android development and as a little project, I'm building a calculator. The way it works is that when a number button is pressed, the number is appended

Solution 1:

You can add tag to every button. In onClick method retrieve tag from button and append it to edit box. OnClickListener for all number buttons will be the same:

public void onClick(View v) {
  String value = v.getTag();
  editText.getText().append(value);
}

So you can use 1 instance of OnClickListener for all buttons.


Post a Comment for "Equivalent Of Set= And GetActionCommand In Android Java?"