Hi Raul,
You could use the Toast.cancel() or Toast.setDuration() method to dismiss
the alert programatically.
To call Toast from a thread other than the main UI thread you can create a
handler in the main UI thread, and then post the runnable in which your
Toast is created to this handler.
final Handler mHandler = new Handler();
Thread t = new Thread() {
public void run() {
mHandler.post(mUpdate);
}
};
t.start();
}
final Runnable mUpdate = new Runnable() {
public void run() {
Toast.makeText(Spad6.this, "New message",
Toast.LENGTH_SHORT).show();
}
};
Thanks,
Megha
On Tue, Apr 1, 2008 at 12:03 PM, Raul Bocter <[EMAIL PROTECTED]> wrote:
> I see Toast being simmilar to AlertDialog. Still it is not a solution for
> me. The docs say the time the Toast is visible could be customizable. I
> don't see how. Anyway, I still get to the Looper problem. The API demos
> indicated make use of a Toast in the event thread. I need to show it in
> another thread. eg:
>
> public void run(){
> // show information dialog 1
>
> // try to do lengthly_stuff_1
>
> // hide information dialog 1
>
> // if lengthly_stuff_1 failed {
> // show information dialog 2
>
> // do lengthly_stuff_2
>
> // hide information dialog 2
> }
> }
>
> Writing this e-mail, I got the idea to show the alert or Toast in the
> event thread ( runOnUIThread() ). It works and like this I can avoid the
> Looper. Ok, but what can I use to hide / dispose it exactly when I want and
> to do this programatically ?
>
>
> regards,
> Raul
>
>
>
>
> On Tue, Apr 1, 2008 at 9:15 PM, Megha Joshi <[EMAIL PROTECTED]> wrote:
>
> > Hi,
> >
> > You can dismiss the dialog shown by showalert() by clicking the back
> > button on the emulator, if your dialog is cancelable.
> >
> > http://code.google.com/android/reference/android/content/Context.html#showAlert(java.lang.CharSequence,%20int,%20java.lang.CharSequence,%20java.lang.CharSequence,%20android.content.DialogInterface.OnClickListener,%20java.lang.CharSequence,%20android.content.DialogInterface.OnClickListener,%20boolean,%20android.content.DialogInterface.OnCancelListener)<http://code.google.com/android/reference/android/content/Context.html#showAlert%28java.lang.CharSequence,%20int,%20java.lang.CharSequence,%20java.lang.CharSequence,%20android.content.DialogInterface.OnClickListener,%20java.lang.CharSequence,%20android.content.DialogInterface.OnClickListener,%20boolean,%20android.content.DialogInterface.OnCancelListener%29>
> >
> > If you want a show an alert which disappears automatically after a
> > specified duration or disappears on calling cancel(), consider using the
> > Toast class instead.
> >
> > Sample code for using Toast:
> > The ApiDemos > apps> AlarmService.java,AlarmController.java
> >
> > Hope this helps!
> >
> > Thanks,
> > Megha
> >
> >
> > On Tue, Apr 1, 2008 at 6:37 AM, Raul Bocter <[EMAIL PROTECTED]>
> > wrote:
> >
> > > never mind that one. it seems to work if I put loop() at the end of
> > > the logic.
> > >
> > > I have another related problem now. I want to show two alerts, one
> > > after the other, as the logic advances. But I can not get rid of the first
> > > alert. Calling cancel() or dismiss() or both does not work. How can I
> > > loose
> > > an alert programatically ?
> > >
> > > regards,
> > > Raul
> > >
> > >
> > >
> > >
> > > On Tue, Apr 1, 2008 at 4:07 PM, Raul Bocter <[EMAIL PROTECTED]>
> > > wrote:
> > >
> > > > Hello,
> > > >
> > > >
> > > > I am trying to show alerts while doing some logic in the background.
> > > > I want to do this in a new thread (not the UI thread). I don't
> > > > understand
> > > > how this should work. As I try to show the alert it throws an exception
> > > > saying i have to call Looper.prepare() first. Ok, I call prepare().
> > > > The alert does not show until Looper.loop()gets called. But after
> > > > loop(), the thread is stuck there. It will not go further. What would
> > > > be a
> > > > solution for this?
> > > >
> > > > regards,
> > > > Raul
> > > >
> > >
> > >
> > >
> > >
> >
> >
> >
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---