-4

Hi i am creating a simple educational game in which user has to press three images in order to proceed to the next level and in next level user has to press 5 images.

i have gone through the on click but i using onIntent intent = new Intent(this.getApplicationContext(), Activity.class); this.startActivity(intent, 0); i am only able to start new activity on single button pressed but i wanted to start new activity when user has finished pressing three image Buttons.

Thanks in advanced.

3 Answers3

3

you can use global int variable and increase it every button click and if its more than your button number open new activity

public int btn = 0;

  MyButton.setOnClickListener(new OnClickListener() 
{
 @Override          
 public void onClick(View v) 
 {              
     if(btn >= 2) {

//open your activity 

}   

else{
btn++;
}       
  }         
});
harsha.kuruwita
  • 1,315
  • 12
  • 21
1

Based on my understanding of your problem,I have provided a possible simple implementation. Use a simple data structure like queue or stack. When a image is tapped, add information about the image to the data structure. After adding the information to data structure see if number of items in data structure is equal to 3 ? if yes check data structure has info about the required three images and not just info about the same image (happens if user taps on same image more than once). If condition is met then call startActivity(). Generalize this so that you can reuse the logic in different activities, irrespective of the number of images.

Jeevan
  • 8,532
  • 14
  • 49
  • 67
-1

Hi i finally achieved my desired activity. now with this after checking two check box app will start new activity.

`private CheckBox chkIos, chkAndroid, chkWindows; private Button btnDisplay; OnClickListener checkBoxListener;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    chkIos = (CheckBox) findViewById(R.id.chkIos);
    chkAndroid = (CheckBox) findViewById(R.id.chkAndroid);
    checkBoxListener =new OnClickListener() {


                public void onClick(View v) {

                    if(chkIos.isChecked()&&chkAndroid.isChecked()) {
                Intent i1=new Intent(getApplicationContext(), Main1.class);
                startActivity(i1);
                if(chkAndroid.isChecked())  {
                    Intent i2=new Intent(getApplicationContext(), Main1.class);
                    startActivity(i1);
                }
            }

        }
    };
    chkIos.setOnClickListener(checkBoxListener);
    chkAndroid.setOnClickListener(checkBoxListener);

}

} `

thanks for all your answers.