I know this might sound very basic but here\'s my problem:
I have an onclickevent listener that\'s supposed to increment the counter indefinitely when it\'s clicked:
t.setOnClickListener(new View.OnClickListener() {
int Counter = 0;
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), R.string.hey, Toast.LENGTH_SHORT).show();
t.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
c.setBackgroundColor(getResources().getColor(R.color.colorAccent));
p.setVisibility(View.VISIBLE);
if (Counter >= 0) {
Counter++;
e.setText("you clicked Click me "+Counter +"number of times");
e.setTextSize(15);
e.setTextColor(getResources().getColor(R.color.colorPrimary));
e.setSingleLine();
}
You could declare 'counter' outside the Activity's oncreate method.
Solved:
myimageView2.setOnClickListener(new OnClickListener() {
int counter = 0;
public void onClick(View v) {
counter ++;
}
});