Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a button and have set its onclick listener that checks the number if times a button was clicked, i used if else statement for doing it. now in the else statement i need to implement a dialoge box. This is the code i used by i'm getting errors. need help

public void onClick(View v) {
			// TODO Auto-generated method stub
			clickCount=clickCount+=1;
			try {
				
				if(clickCount<=5){
					Intent intent = new Intent(ACTION_SCAN);

					intent.putExtra("SCAN_MODE", "PRODUCT_MODE");

	       		startActivityForResult(intent, 0);
	
				}
				else
				{
					AlertDialog.Builder alertdialogBuilder=new AlertDialog.Builder(getApplicationContext());
					alertdialogBuilder.setMessage(R.string.decision);
					alertdialogBuilder.setPositiveButton(R.string.positive_button, new DialogInterface.OnClickListener() {
						
						@Override
						public void onClick(DialogInterface dialog, int which) {
							// TODO Auto-generated method stub
							Intent positveActivity = new Intent(getApplicationContext(),MainActivity.class);
				            startActivity(positveActivity);	
						}
					}); 
					 AlertDialog alertDialog = alertdialogBuilder.create();
				      alertDialog.show();
					//Toast.makeText(getApplicationContext(), "Reached Maximum scan Primay" , Toast.LENGTH_LONG).show();
					//Intent i1=new Intent(getApplicationContext(),MainActivity.class);
					//startActivity(i1);
				}
	             //start the scanning activity from the com.google.zxing.client.android.SCAN intent

							} catch (ActivityNotFoundException anfe) {

       //on catch, show the download dialog

			showDialog(Secondary.this, "No Scanner Found", "Download a scanner code activity?", "Yes", "No").show();

			}

		}	
		});
}
Posted
Comments
Style-7 20-May-15 2:48am    
What is error?
Rahul Ramakrishnan 20-May-15 3:49am    
unable to add window token null for an application
Richard MacCutchan 20-May-15 3:48am    
What errors, and where do they occur?
Rahul Ramakrishnan 20-May-15 3:53am    
>unable to add window token for an application
>Secondary onClick
>android.view.WindowManagerImpl.addView

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900