[TinyTut] - Displaying a Messagebox

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

handle open connection with messagebox

Postby suharyadi » Mon Mar 10, 2008 11:29 am

hi everyone
i have application that request openconnection, but if my server is off / nothing
my applicatio is like not responding, and alwasy show message wait or end activity
anyone can help me handle it
suharyadi
Freshman
Freshman
 
Posts: 6
Joined: Wed Dec 26, 2007 10:09 am

Top

Postby plusminus » Mon Mar 10, 2008 9:45 pm

Hello suharyadi,

Put it to a thread and interrupt it when you think it is time for a timeout.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Re: [TinyTut] - Displaying a Messagebox

Postby saty_32016 » Mon Mar 17, 2008 5:13 am

plusminus wrote:
[TinyTut] - Displaying a Messagebox


What you learn: You will learn how easy it is, to display a MessageBox (showAlert(...)).

Difficulty: 0 of 5 :roll:

What it will look like:
Image


Description
This has been a very common question, as in "normal" Java a MessageBox was displayed with code like:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. JOptionPane.showMessageDialog(...);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4

in Android you can do almost the same with the following code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. showAlert("A funny title", "MessageBoxes rule extremely!", "Hit Me!", false);
  2. // Where the definition of the function is (simplest of 4 different):
  3. showAlert(CharSequence title, CharSequence message, CharSequence buttonText, boolean cancelable)
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


Regards,
plusminus


is it possible to have a popoup box with a facility to browse system folder's?
or can we populate total system folders here on emulator
saty_32016
Developer
Developer
 
Posts: 27
Joined: Mon Mar 10, 2008 4:47 am

Postby Ventrix » Tue Jul 01, 2008 10:31 am

I have this code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.app.Activity;
  2.  
  3. import android.os.Bundle;
  4.  
  5. import android.content.DialogInterface;
  6.  
  7. import android.content.DialogInterface.OnClickListener;
  8.  
  9. import android.content.Intent;
  10.  
  11. public class Testing extends Activity {
  12.  
  13.         /** Called when the activity is first created. */
  14.  
  15.         @Override
  16.  
  17.     public void onCreate(Bundle icicle) {
  18.  
  19.         super.onCreate(icicle);
  20.  
  21.         setContentView(R.layout.main);
  22.  
  23.         showAlert("A funny title",0, "MessageBoxes rule extremely!", "Hit Me!", new DialogInterface.OnClickListener(){
  24.  
  25.   [s]          @Override[/s]
  26.  
  27.             public void onClick(DialogInterface arg0, int arg1) {
  28.  
  29.                  setContentView(R.layout.main1);
  30.  
  31.             }
  32.  
  33.        }, false, null);
  34.  
  35.     }
  36.  
  37. }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


and I'm getting a "The method onClick(DialogInterface, int) of type new DialogInterface.OnClickListener(){} must override a superclass method" error.


EDIT The solution was simple, I had to remove the @Override line before the onClick method.
http://www.androidgreece.gr - Greek Android Community
User avatar
Ventrix
Junior Developer
Junior Developer
 
Posts: 11
Joined: Tue Mar 04, 2008 11:47 pm
Location: Greece

Postby nono35 » Mon Jul 21, 2008 4:50 pm

hi everyboy,

is it possible to drag this dialog ?
I have a MapActivity under this dialog and I want to move this dialog in order to click on the map and get a position that the dialog will receive...

Thanks for reply :)
nono35
Freshman
Freshman
 
Posts: 4
Joined: Mon Jul 21, 2008 4:40 pm

Postby mrdanger » Mon Sep 08, 2008 10:24 am

hello everybody,

I was in the vacation for 1 1/2 month. Now i will work on my project, but the showAltert not working. Is this correct?
mrdanger
Junior Developer
Junior Developer
 
Posts: 10
Joined: Tue Jun 17, 2008 3:22 pm
Location: Hamburg, Germany

Top

Postby Gurbuh » Mon Sep 08, 2008 9:55 pm

I also tried to follow this tutorial. But showAlert() didn't work so I googled it and found out that in my version of the SDK (0.9 beta) showAlert is replaced by AlertDialog. So maybe the tutorial could be updated? :P
Gurbuh
Junior Developer
Junior Developer
 
Posts: 17
Joined: Mon Sep 08, 2008 9:49 pm
Location: The Netherlands

Postby haden » Thu Sep 11, 2008 12:04 pm

Gurbuh wrote:I also tried to follow this tutorial. But showAlert() didn't work so I googled it and found out that in my version of the SDK (0.9 beta) showAlert is replaced by AlertDialog. So maybe the tutorial could be updated? :P



HI gurbuh, try this out.

showAlert("A funny title",1, "MessageBoxes rule extremely!", "Hit Me!", false);

there is an additional int variable.. not sure what its for.
haden
Experienced Developer
Experienced Developer
 
Posts: 74
Joined: Thu Sep 11, 2008 11:51 am

Postby plusminus » Thu Sep 11, 2008 2:22 pm

Gurbuh wrote:I also tried to follow this tutorial. But showAlert() didn't work so I googled it and found out that in my version of the SDK (0.9 beta) showAlert is replaced by AlertDialog. So maybe the tutorial could be updated? :P


Hello Gurbuh,

you should be using [font=Courier New]android.app.AlertDialog.Builder[/font] since 0.9 it works like this (syntax may be wrong):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. new android.app.AlertDialog.Builder().setTitle("MyTitle").setMessage("").setIcon(R.drawable.icon).create().show();
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Gurbuh » Thu Sep 11, 2008 3:25 pm

So they made it less simple :P Thanks for the heads up!
Gurbuh
Junior Developer
Junior Developer
 
Posts: 17
Joined: Mon Sep 08, 2008 9:49 pm
Location: The Netherlands

tutorial how to use AlertDialog.Builder

Postby Artur79 » Sun Sep 28, 2008 1:19 pm

I've found nice tutorial how to show dialogs with AlertDialog.Builder

http://www.maximyudin.com/2008/02/25/an ... lications/

Here's an example how to display message with a button to close alert.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. new AlertDialog.Builder(MainActivity.this)
  2.  
  3.         .setTitle("Simple Alert Dialog")
  4.  
  5.         .setMessage("Are you sure that you want to quit?")
  6.  
  7.         .setNegativeButton("Yes", new DialogInterface.OnClickListener() {
  8.  
  9.  
  10.  
  11.                 public void onClick(DialogInterface dialog, int whichButton) {
  12.  
  13.  
  14.  
  15.                 }
  16.  
  17.         })
  18.  
  19. .show();
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


quite combined, is there simplier way ?
Artur79
Developer
Developer
 
Posts: 26
Joined: Fri Sep 26, 2008 12:53 pm

Postby plusminus » Mon Sep 29, 2008 3:58 am

Hello Artur,

I think this is pretty easy. :? What would you simplify :?:

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby EwanG » Wed Oct 08, 2008 12:59 am

OK, I've been "playing" with this for some time, and I'm not getting anywhere. I don't get a compile error, but when I get to where I do the dialog, the program crashes.

Basically I've followed one of the Google examples and have a thread class and a view class. So I get to:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         public void setState(int mode, CharSequence message) {
  2.  
  3.             synchronized (mSurfaceHolder) {
  4.  
  5.                 mMode = mode;
  6.  
  7.  
  8.  
  9.         .... {lines removed for decision tree} ....
  10.  
  11.  
  12.  
  13.                     else if (mMode == STATE_WIN){
  14.  
  15.                     // We beat a level, so now it's time to add to the win counter,
  16.  
  17.                     // move to the next level
  18.  
  19.                         str = res.getString(R.string.mode_win_prefix)
  20.  
  21.                                 + mWinsInARow + " "
  22.  
  23.                                 + res.getString(R.string.mode_win_suffix);
  24.  
  25.                         mMyLevel ++;
  26.  
  27.                         switch(mMyLevel) {
  28.  
  29.                         case 1:
  30.  
  31.                             mBackgroundImage = BitmapFactory.decodeResource(res,
  32.  
  33.                                     R.drawable.level2);
  34.  
  35.                             mBackgroundImage = Bitmap.createScaledBitmap(
  36.  
  37.                                     mBackgroundImage, mCanvasWidth, mCanvasHeight, true);
  38.  
  39.                             break;
  40.  
  41.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4

and I'd like to add a dialog or screen that "sets up" the scenario for the next level. If I try to put the dialog here, the app crashes. Without the dialog it runs fine. I've made sure I have all the supporting libraries, and I'm not getting any warnings or errors during the build, so I'm not sure what I'm doing wrong.

Maybe something changed in the 1.x SDK?
EwanG
Freshman
Freshman
 
Posts: 5
Joined: Sat Sep 20, 2008 3:37 pm
Location: San Antonio, TX

Postby EwanG » Mon Oct 13, 2008 9:38 pm

Bump...

For the time being I've created another activity and then just switch views, but that seems like overkill for what I want. Any suggestions?
EwanG
Freshman
Freshman
 
Posts: 5
Joined: Sat Sep 20, 2008 3:37 pm
Location: San Antonio, TX

Postby MrSnowflake » Mon Oct 13, 2008 10:14 pm

It's a wild guess, but you probably can't make Dialogs from non-ui threads! So find a way to post the building of the dialog to the ui thread (the activity), for example using a Handler object.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top
PreviousNext

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests