Hello Guys im new on this Website so if I make any mistakes please forgive me. For the School I need to code an App and I want to code an app like the old Egg app where you needed to click on for like 1.000.000 times.
My Counter works but I wanted to let the Egg break. For this I wanted to use an if statement so I can make it break after like 200 times and so on.
My Problem is that if I'm pressing the button the Image switch in the first time. Not as I expected in the third time
Do anyone knows what my problem is?
PS: I'm new in java so maybe the code isn't sexy
package com.example.die_vierte;
import android.content.Intent;
import android.media.Image;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.webkit.SafeBrowsingResponse;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private Object TextView;
int eggcounter;
ImageButton ImgButton;
android.widget.TextView textClicks;
private Object SafeBrowsingResponse;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
eggcounter = 10000000;
final ImageButton ImgButton = findViewById(R.id.eggBtn);
ImgButton.setOnClickListener(
new View.OnClickListener() {
public void onClick(View view) {
eggcounter = eggcounter - 1;
updateEgg();
if (eggcounter > 999998) {
ImgButton.setImageResource(R.drawable.egg_2);
}
}
}
);
public void updateEgg() {
textClicks = (TextView) findViewById(R.id.textScore);
textClicks.setText(eggcounter + " ");
}
elsestatement after theif