开发者

Notifiy the user in a Thread

Code:

final ProgressDialog pd = ProgressDialog.show(Main.this,"","Loading. Please wait...", true);
pd.show();

Thread t = new Thread()
           {
               public void run()
               {
                   result = GetData("link", nameValuePairs);
                   pd.dismiss();
         开发者_Python百科          if(result.contains("Logged IN"))
                   { 
                       user=etuser.getText().toString();
                   }
                   else
                   {
                       fail();
                   }
               }
           };
t.start();

Fail Function:

public void  fail ()
{
    final TextView tverror = new TextView(this);
    tverror.setText("FAIL");
    linear_l.addView(tverror);
}

Error: It isn't possible to add a view during the run in the thread.

Is there any workaround?


Do not attempt to modify the UI from a background thread. Use onPostExecute() in an AsyncTask. Or, use a Handler. Or, use post() on any View. Or, use runOnUiThread().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜