I'm trying to learn Android by creating a calculator app. I have buttons with Ids button0
to button9
. On clicking the button, their value should be be added to textViewAbove but I can't seem to be able to convert an integer into a string. I feel that the Android studio is taking my toString()
method to be of integer.toString()
type.
Code:
int[] buttonId = {R.id.button0, R.id.button1, R.id.button2, R.id.button3, R.id.button4,
R.id.button5, R.id.button6, R.id.button7, R.id.button8, R.id.button9};
Button[] bt = new Button[10];
for (int i = 0; i < 10; i++) { //If this doesn't work then do it separately.
final int I = i;
bt[I] = (Button) findViewById(buttonId[I]);
bt[I].setOnClickListener(
new Button.OnClickListener() {
public void onClick(View v) {
textViewAbove.append(toString(I));
//Enter action methods here.
}
}
);
}
Error:
Error:(111, 50) error: method toString in class Object cannot be applied to given types;
required: no arguments
found: int
reason: actual and formal argument lists differ in length
Note that the code is inside the onCreate
method in the MainActivity
class.