Tuesday, August 17, 2010

[android-developers] Re: Threading confusion

You might want to create a new handler in your main thread to update
all UI stuff cos i think UI updating is not allowed in other threads
besides the main one.

On Aug 18, 1:29 pm, Mystique <joven.ch...@gmail.com> wrote:
> Hi all, please help me look at my code. Many thanks.
>
> --- code ---
> private Handler handler = new Handler();
> private ProgressDialog dialog;
>
> final Runnable runInUIThread = new Runnable()  {
>     public void run() {
>         dialog.dismiss();
>     }
>
> };
>
> private void DoThis() {
>     dialog = new ProgressDialog(Main.this);
>     dialog.setTitle("Title");
>     dialog.setMessage("Text");
>     dialog.show();
>
>     Thread newTask = new Thread() {
>         @Override
>          public void run() {
>                 Looper.prepare();
>                 DoThat();
>                 handler.post(runInUIThread);
>                 Looper.loop();
>          );
>          newTask.start();
>        }}
>
> --- code ---
>
> Is it possible to use test.setText("something") in this thread to
> update a Button text or TextView in the LinearLayout after the dialog
> is dismissed? I try cheating placing:
>
> test.setVisibility(View.INVISIBLE);
> test.setText("something");
> test.setVisibility(View.VISIBLE);
>
> after dialog.show();
> It kind of updated the text when the dialog open. I want to do it
> after the dialog was dismissed. What is the correct way to implement
> this in my thread?

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate