vendredi 9 juin 2017

Trying to start new activity with If (contalPanel == 4)?

Hallo im new to android programming. I'm trying to start activity when the countPanel has the int 4 so if countPanel == 4. It is not working could you please help me. So when i put the staractivity statement in if statement it doesnt work i dont know why

public class MainActivity extends AppCompatActivity {
int countPanel = 0;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set the content of the activity to use the activity_main.xml layout file
    setContentView(R.layout.activity_main);


        // Find the View that shows the numbers category
        TextView image = (TextView) findViewById(R.id.countPanelXML);


        // Set a click listener on that View
        image.setOnClickListener(new View.OnClickListener() {
            // The code in this method will be executed when the numbers category is clicked on.
            @Override
            public void onClick(View view) {


                        // Create a new intent to open the {@link NumbersActivity}
                        //Intent imageIntent = new Intent(MainActivity.this, ImageActivity.class);

                    // Start the new activity
                if (countPanel == 4 || countPanel == 8 || countPanel == 12 || countPanel == 16 || countPanel == 20) {
                    Intent imageIntent = new Intent(MainActivity.this, ImageActivity.class);
                    startActivity(imageIntent);
                }
            }
        });

}





public void displayCountingPanel(int counting) {
    TextView countingView = (TextView) findViewById(R.id.countPanelXML);
    countingView.setText(String.valueOf(counting));
}

public void addTwoRakkah(View view) {
    if (countPanel == 20) {
        Toast.makeText(this, "Maximum amount of Taraweeh reached", Toast.LENGTH_SHORT).show();
        return;
    }

    displayCountingPanel(countPanel += 2);
}

public void addTreeRakkah(View view) {
    if (countPanel == 20) {
        Toast.makeText(this, "Maximum amount of Taraweeh reached", Toast.LENGTH_SHORT).show();
        return;
    }

    displayCountingPanel(countPanel += 4);
}

public void resetScore(View view) {
    countPanel = 0;

    displayCountingPanel(countPanel);
}

}

Aucun commentaire:

Enregistrer un commentaire