2010-12-11 49 views
0

我開始創建活動的Timertask。計時器任務監聽麥克風輸入並確定聲音頻率。每當頻率超過一定範圍時,我需要顯示帶有消息的對話框。下面的代碼對我來說看起來不錯,但是DIalog框不會彈出。任何建議,將不勝感激定時器任務中的對話框

Context mContext = getApplicationContext(); 
    System.err.println("Inside Dialog"); 
    Dialog dialog = new Dialog(mContext); 
    dialog.setContentView(R.layout.entryofferdialog); 
    dialog.setTitle("This is my custom dialog box"); 
    dialog.setCancelable(true); 
    // set up text 
    TextView text = (TextView) dialog.findViewById(R.id.TextView01); 
    text.setText(":LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL"); 

    // set up button 
    Button button = (Button) dialog.findViewById(R.id.Button01); 
    button.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      finish(); 
     } 
    }); 
    // now that the dialog is set up, it's time to show it 
    dialog.show(); 
} 
+1

是否有任何錯誤,或者在控制走這裏面計時器,把日誌,然後嘗試檢查..... – viv 2010-12-11 05:48:49

+0

沒有錯誤..那是什麼讓我爲難 – Ananth 2010-12-11 14:56:12

回答

1

我曾經處理程序來解決它。

1

我用這樣的Handler。

public class Lessons extends Activity{ 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.lessons); 

    Handler handler = new Handler(); 

    handler.postDelayed(new Runnable() { 
     public void run() { 
      Dialog dialogLessons = new Dialog(Lessons.this); 
      dialogLessons.setContentView(R.layout.test_dialog_box); 
      dialogLessons.setTitle("Lesson test dialog title"); 
      dialogLessons.setCancelable(false); 

      TextView text = (TextView) 
        dialogLessons.findViewById(R.id.textView1); 
      text.setText(R.string.lots_of_text); 

      dialogLessons.show(); 

     } 
    }, 2000); 
} 

}

相關問題