我在Oncreate of Activity中启动Timertask。计时器任务侦听麦克风输入并确定声音频率。每当频率超过一定范围时,我需要显示带有消息的Dialogbox。以下代码对我来说很好,但是没有弹出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();
}
答案 0 :(得分:1)
我曾经让Handlers解决它。
答案 1 :(得分:1)
我使用了像这样的处理程序。
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);
}
}