Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: AlertDiialog

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default AlertDiialog

    Hi

    Can someone explain me why the second if in this code never is executed.

    @SuppressWarnings("deprecation")
    	public void showAnulacao(View v) {
    		String result = "Os dias anulados foram:";
    		Double totalAmount = 0.0;
    		for (Refeicao p : boxAdapter.getBox()) {
    			if (p.selected) {
    				result += "\n" + p.dia;
    				totalAmount += p.preco;
    				AlertDialog alertDialog = new AlertDialog.Builder(CantinaDiurnoActivity.this).create();
    				alertDialog.setTitle("Informação");
    				alertDialog.setMessage(result + "\n" + "Creditamos-lhe: " + totalAmount + "€");
    				alertDialog.setIcon(R.drawable.tick);
    				alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
    					public void onClick(DialogInterface dialog, int which) {
    						finish();
    					}
    				});
    				alertDialog.show();
    			}
    			if(!p.selected){
    				AlertDialog alertDialog = new AlertDialog.Builder(CantinaDiurnoActivity.this).create();
    				alertDialog.setTitle("Erro!");
    				alertDialog.setMessage("Não efetuou nenhuma seleção!");
    				alertDialog.setIcon(R.drawable.delete);
    				alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
    					public void onClick(DialogInterface dialog, int which) {
    						finish();
    					}
    				});
    				alertDialog.show();	
    			}
    		}
    	}

    The checkbox should be executed in the first "if" if it is checked, or the second if if none are checked...any help please??

    Thanks

  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: AlertDiialog

    p.selected has to return false for the second if block to execute

    Verify that p.selected returns false when you think it should