我想顯示在AsyncTask中的其他類中的AlertDialog。 例>有沒有辦法在AsyncTask中顯示AlertDialog?
public class WardListAsyncTask extends AsyncTask<HashMap<String, String>, String, Object> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Object doInBackground(HashMap<String, String>... params) {
...
}
@Override
protected void onPostExecute(Object result) {
ConfirmAlertDialog(ez_WardList.this,"HI?");
//this method is in another Class & I want to use this method another Asynctask also..
}
和ConfirmAlertDialog是...
Context g_ctx;
String g_content;
public void ez_ConfirmAlertDialog(Context ctx, String content) {
this.g_ctx=ctx;
this.g_content=content;
runOnUiThread(new Runnable() {
@Override
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(g_ctx, AlertDialog.THEME_HOLO_LIGHT);
builder.setMessage(g_content).setPositiveButton(getString(R.string.kor_confirm),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
alertDialog.getWindow().setLayout(displayWidth/2, LayoutParams.WRAP_CONTENT);
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(Color.rgb(10, 174, 239));
}
});
}
我覺得g_ctx.class.runonuiThread ......但我不能叫runonuithread ...
我怎麼能解決這個問題?
調用'#Context.runonuithread'。 – Sanoop
相關:http://stackoverflow.com/questions/13974661/runonuithread-vs-looper-getmainlooper-post-in-android – Sufian