2010-12-11 6 views
0

활동 생성 중 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(); 
} 
+1

에 오류가 있습니까, 또는 컨트롤이 ..... – viv

+0

오류를 확인하지하려고 다음 로그를 넣고,이 타이머 내부 것입니다 .. 나 퍼즐 이잖아 – Ananth

답변

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); 
} 

}