Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning Android Application Development
|
BOOK: Beginning Android Application Development
This is the forum to discuss the Wrox book Beginning Android Application Development by Wei-Meng Lee; ISBN: 978-1-1180-1711-1
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Android Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 2nd, 2012, 11:41 PM
Registered User
 
Join Date: Jul 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 2: Displaying a Dialog Window Using and Activity

I'm getting an error message in my progress dialog
Code:
        _progressHandler = new Handler() {
        public void handleMessage(Message msg) {
        	super.handleMessage(msg);
        	if (_progress >= 100) {
        		_progressDialog.dismiss();
        	} else {
        		_progress++;
        		_progressDialog.incrementProgressBy(1);
        		_progressHandler.sendEmptyMessageDelayed(0, 100);
       		}
       	}
    };
}
    
    @Override
    protected Dialog onCreateDialog(int id) {
    	switch (id) {
    	case 0:
    		return new AlertDialog.Builder(this)
    		.setIcon(R.drawable.ic_launcher)
    		.setTitle("This is a dialog with some simple text...")
    		.setPositiveButton("OK", new
    				DialogInterface.OnClickListener() {
    				public void onClick(DialogInterface dialog,
    				int whichButton)
    				{
    					Toast.makeText(getBaseContext(),
    							"OK Clicked!", Toast.LENGTH_SHORT).show();
    				}
    		})
    		.setNegativeButton("Cancel", new
    				DialogInterface.OnClickListener() {
    				public void onClick(DialogInterface dialog,
    					int whichButton)
    				{
    					Toast.makeText(getBaseContext(),
    							"Cancel Clicked!", Toast.LENGTH_SHORT).show();
    				}
    		})
    		.setMultiChoiceItems(items, itemsChecked, new
    				DialogInterface.OnMultiChoiceClickListener() {
    					@Override
    					public void onClick(DialogInterface dialog, int which,
    					boolean isChecked) {
    						Toast.makeText(getBaseContext(),
    							items[which] + (isChecked ? "Checked!":
    							"Unchecked!"),
    							Toast.LENGTH_SHORT).show();
    					}
    			}
    		)
    		.create();
    	case 1:
    		_progressDialog =new ProgressDialog(this);
    		_progressDialog.setIcon(R.drawable.ic_launcher);
    		_progressDialog.setTitle("Downloading files...");
    		_progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    		_progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Hide", new
    			DialogInterface.OnClickListener() {
    			public void onClick(DialogInterface dialog,
    				int whichButton)
    			{
    				Toast.makeText(getBaseContext(),
    						"Hide clicked!", Toast.LENGTH_SHORT).show();
    			}
    		});
    		return _progressDialog;
    	}
    	return null;
    }
}
1. In the line "_progressHandler.sendEmptyMessageDelayed(0, 100);" This Handler class must be static or leaks might occur." I'm just not totally sure what this means.
2. In the line ' "Hide clicked!", Toast.LENGTH_SHORT).show();' I get the error message "syntax error on token(s), misplaced construct(s)." I haven't been able to find an error in the code from the book, so I assume something is out-of-date.
Please help! <3
 
Old August 3rd, 2012, 06:39 PM
Authorized User
 
Join Date: Nov 2011
Posts: 86
Thanks: 3
Thanked 5 Times in 5 Posts
Default

Hi ethomps2

I not sure about #1. How did you define _progressHandler?
Actually I get the same warring in my code. I just ignore it. At least until know more.

#2 looks all right to me. I can not find any errors in the code you posted.

What version of Java and Android are you using?

Cliff
__________________
"Software to the Stars"
Failure is not an option. It comes bundled with your Microsoft products.

Last edited by Cliff2310; August 3rd, 2012 at 07:01 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help me please to close Dialog window. KirillOssokin Java Basics 1 February 14th, 2012 07:38 AM
Communication between a parent window and a modal dialog window swizz182g Javascript 0 August 27th, 2009 04:41 PM
Displaying modal dialog from server code gp_mk HTML Code Clinic 16 July 1st, 2007 07:55 AM
Chapter 17 - Displaying the dialog box davidd31415 BOOK: Beginning Visual C++ 6 1 September 24th, 2006 04:46 PM
Modal dialog window eldanh ASP.NET 1.0 and 1.1 Basics 0 August 10th, 2004 02:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.