开发者

Notifiy the user in a Thread

开发者 https://www.devze.com 2023-01-31 17:39 出处:网络
Code: final ProgressDialog pd = ProgressDialog.show(Main.this,\"\",\"Loading. Please wait...\", true);

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

精彩评论

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