2012-03-26 85 views
0

我有想解除進度對話框後向用戶敬酒的情況。 我怎麼能這樣做所有的代碼只執行Toast.showMessage(,「」,,)。show is not working。 下面是我的代碼請看看這個,給我的建議。代碼顯示在android中關閉進度對話框後的Toast消息?

if (common.split.equals("failure")) { 

       try { 

        if (this.pd.isShowing()) { 
         this.pd.dismiss(); 
        } 


        Toast.makeText(getApplicationContext(), "No data found", 
          Toast.LENGTH_SHORT).show(); 
       } catch (Exception e) { 
        // TODO: handle exception 
       } 

      } 
+0

上面粘貼的代碼在哪裏執行? – Gaurav 2012-03-26 13:09:25

+0

如果解決了,請接受答案 – 2013-02-15 09:12:15

回答

2

第一件事:永遠趕不上所有例外:

} catch (Exception e) { 
    // TODO: handle exception 
} 

與e.getMessage()或e.printStackTrace()記錄異常出現,有可能是當你被解僱崩潰對話框,因爲你沒有記錄它,所以你不會確定問題是否在吐司面前。

並與例外指定你想趕上這樣的:

catch (IOException e) 

否則,你可以捕捉空指針異常,其中大部分時間是程序員的錯誤:)

2

試試這個:

this.pd.setOnDismissListener(new OnDismissListener() { 

      @Override 
      public void onDismiss(DialogInterface arg0) { 
       // TODO Auto-generated method stub 
       Toast.makeText(getApplicationContext(), "Text of Toast", Toast.LENGTH_SHORT).show(); 
      } 
     });