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()
.
精彩评论