I want to create button with text = \"SomeText\" on center of this button and \"0\" on right part of button. Where \"0\" is the Counter and when I click this button Counter++ i
There are several options.
Create a static variable:
private static int buttonClickCount = 0;
public void but1_Count(View v){
buttonClickCount++;
v.settext("Clicked " + buttonClickCount);
}
Create custom button by extending base button class and implement onClickListener:
public class MyButton extends Button implements View.OnClickListener {
private int counter = 0;
public MyButton(...){
this.setOnClickListener(this);
}
public void onClick(View v) {
counter++;
v.setText("Clicked"+counter);
}
}
Extract value from clicked button, parse it as int, and increment:
public void but1_count(View v){
int curr = Integer.parseInt(v.getText().toString());
v.setText(""+curr);
}