I'm new to programming android / java and then this error came up.
public class Activity_2 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity2);
getSupportActionBar().hide();
Spinner alvos = (Spinner) findViewById(R.id.alvos);
Spinner posicoes = (Spinner) findViewById(R.id.posicoes);
ImageButton hit = (ImageButton) findViewById(R.id.hit);
ImageButton miss = (ImageButton) findViewById(R.id.miss);
int contador = getIntent().getIntExtra("cont", 0);
int sum = getIntent().getIntExtra("targ", 0);
Integer [] arrayAlvos = new Integer[sum];
for(int i=1; i<=sum; i++){
arrayAlvos[i-1]=i;
}
ArrayAdapter<Integer> adapter = new ArrayAdapter<Integer>(this,android.R.layout.simple_dropdown_item_1line, arrayAlvos);
alvos.setAdapter(adapter);
ArrayAdapter pos = ArrayAdapter.createFromResource(this, R.array.posicao, android.R.layout.simple_dropdown_item_1line);
posicoes.setAdapter(pos);
hit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(tiro.this);
alert.setMessage("Certo");
alert.show();
contador++;
}
});
miss.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(tiro.this);
alert.setMessage("Errado");
alert.show();
contador++;
}
});
}
}
I created the variable int contador = getIntent().getIntExtra("cont", 0);
to know the limit.
Then on the part of the buttons whenever I clicked a button it would increment +1 the counter variable. But in the part where I have contador++
it gives me this error:
variable counter is accessed from within inner class needs to be declared final android
Only I can not change to the end because my goal is to always be to change the value. Any solution?!