0
這是我的代碼,好像一切都很好,但是當應用程序開始時不會關閉ProgressDialog,它可以取消但不會丟失,並且它自應用程序啓動後就會顯示,不是suposed要這樣ProgressDialog沒有關閉
\t private void displayView(int position) {
\t \t final int thePos=position;
\t \t final ProgressDialog myProgressDialog = ProgressDialog.show(MainActivity.this, "", "Procesando...", true);
\t \t myProgressDialog.setCancelable(true);
\t \t new Thread(new Runnable() {
public void run() {
try { \t
\t Thread.sleep(2000);
\t \t MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
\t
\t \t // update the main content by replacing fragments
\t \t Fragment fragment = null;
\t \t switch (thePos) {
\t \t /*case 0:
\t \t \t fragment = new HomeFragment();
\t \t \t break;*/
\t \t case 1:
\t \t \t fragment = new HomeFragment();
\t \t \t break;
\t \t case 2:
\t \t \t fragment = new CalendarioFragment();
\t \t \t break;
\t \t case 5:
\t \t \t fragment = new ContactoFragment();
\t \t \t break;
\t \t case 6:
\t \t \t fragment = new OnclickFragment();
\t \t \t break;
\t \t default:
\t \t \t break;
\t \t }
\t \t if (fragment != null) {
\t \t \t try{
\t \t \t FragmentManager fragmentManager = getFragmentManager();
\t \t \t fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();
\t \t \t // update selected item and tit|le, then close the drawer
\t \t \t mDrawerList.setItemChecked(thePos, true);
\t \t \t mDrawerList.setSelection(thePos);
\t \t \t setTitle(navMenuTitles[thePos]);
\t \t \t mDrawerLayout.closeDrawer(mDrawerList);
\t \t \t }
\t \t \t catch(Exception E)
\t \t \t {
\t \t \t \t Log.e("MainActivity", "Error in creating fragment");
\t \t \t }
\t \t }
\t \t else {
\t \t \t // error in creating fragment
\t \t \t Log.e("MainActivity", "Error in creating fragment");
\t \t }
\t }});
} \t
\t catch (Throwable t) {
// just end the background thread
Log.i("Animation", "Thread exception " + t);
}
}
private void threadMsg(String msg) {
if (!msg.equals(null) && !msg.equals("")) {
Message msgObj = handler.obtainMessage();
Bundle b = new Bundle();
b.putString("message", msg);
msgObj.setData(b);
handler.sendMessage(msgObj);
}
}
// Define the Handler that receives messages from the thread and update the progress
private final Handler handler = new Handler() {
public void handleMessage(Message msg) {
String aResponse = msg.getData().getString("message");
if ((null != aResponse)) {
myProgressDialog.dismiss();
}
}
}; \t
})
\t .start(); } //After call start method thread called run Method
任何人可以看到錯誤?請告訴我
'當應用程序啓動doesn't關閉ProgressDialog,'。 ???當應用程序啓動時,它應該先顯示一個ProgressDialog,然後才能關閉它。您忘記告訴對話何時應該關閉。此外,你也沒有告訴你顯示它的位置/時間。 – greenapps