Wrox Programmer Forums
|
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 July 22nd, 2012, 05:52 PM
Registered User
 
Join Date: Jul 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cannot get this to work

package com.example.dialog;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;


public class MainActivity extends Activity {
CharSequence[] items = { "Google", "Apple", "Microsoft" };
boolean [] itemsChecked = new boolean [items.length];

/** called when the activity is first created */


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


Button btn = (Button) findViewById(R.id.btn_dialog);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(0);
}
});
}

@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 0:

return new AlertDialog.Builder(this)
.setIcon(R.drawable.icon)
.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 on Click(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(),
item[which] =+ (isChecked ? " checked!":)
"unchecked !"),
Toast.LENGTH_SHORT) .SHOW()
}
}
}

)
.Create();
}
return null;
}
}



}

public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);

return true;
}
}
 
Old July 28th, 2012, 08:14 PM
Authorized User
 
Join Date: Nov 2011
Posts: 86
Thanks: 3
Thanked 5 Times in 5 Posts
Default

Hi geomalak
What do you mean "Cannot get this to work"?
What error(s) are you getting? What does it do or not do?
You must give us something to work with.
Cliff
__________________
"Software to the Stars"
Failure is not an option. It comes bundled with your Microsoft products.
 
Old August 2nd, 2012, 11:21 PM
Registered User
 
Join Date: Jul 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK, so I think this is what you do. I had two errors when I did it: the
Code:
Button btn = (Button) findViewById(R.id.btn_dialog);
which shows an error but you just need to quit eclipse and restart it. It's just a glitch.
The second:
Code:
.setIcon(R.drawable.icon)
should be replaced with
Code:
.setIcon(R.drawable.ic_launcher)
As long as everything else is by-the-book it should work
 
Old August 3rd, 2012, 06:21 PM
Authorized User
 
Join Date: Nov 2011
Posts: 86
Thanks: 3
Thanked 5 Times in 5 Posts
Default

Hi ethomps2
OK, so now it works?
Again, What error(s) are you getting? What does it do or not do?
What does LogCat say?
Cliff
__________________
"Software to the Stars"
Failure is not an option. It comes bundled with your Microsoft products.
 
Old August 5th, 2012, 02:22 AM
Registered User
 
Join Date: Jul 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes it works now. I can't remember what the errors were specifically, I just couldn't run the debugger at all. Those were just probably the out-of-date stuff I found in the code as it was written in the book and what I did to fix them.
 
Old August 5th, 2012, 02:24 AM
Registered User
 
Join Date: Jul 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

And just to clarify, I did not originally post this thread--I was just trying to answer the question.





Similar Threads
Thread Thread Starter Forum Replies Last Post
SMS API does not work online but work fine offline. Tonik Beginning PHP 1 January 4th, 2013 08:30 AM
Chapter 1 Ctrl+F5 don't work, F5 does work? jimboak BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 7 June 29th, 2008 03:46 AM
why does it not work pauljames BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 7 January 16th, 2008 03:17 AM
Why Does This Work? Little Shell VB How-To 2 October 13th, 2006 05:26 PM





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