views:

73

answers:

2

friends,

i am using following code to display progress on andorid activity when i call web service method to getposts it show progress. but when call of serivce is complete my application gets crashed.

please guide what mistake am i doing or any other alternative way to achieve this goal?

mProgressStatus = 0;
  Thread th=new Thread(new Runnable() {
   public void run() {
    if (mProgressStatus < 100) {
     myProgressBar.setVisibility(View.VISIBLE);
    } else {
     myProgressBar.setVisibility(View.GONE);
    }
   }

  });


    th.start();

  results = p.GetPosts(p, PageSize, adap.getCount());

  mProgressStatus=100;

th.stop();

A: 

So, if your application crashes, maybe you should look at the error message first? Or at least provide it for us.

(A tip: I read three posts of you today and you always have trouble with the first/last lines of your code pasting, please check you code pasting before you submit a question...)

WarrenFaith
ERROR/AndroidRuntime(1519): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
UMMA
+1  A: 

Try creating the progress bar inside the new thread instead.

Macarse