onHandleIntent()
クラスのメソッドでカスタムダイアログを開きたいのです IntentService
が、このメソッドでダイアログを表示するコードを書くとエラーが表示されます
The method findViewById(int) is undefined for the type MyAlarmService
誰かがこの問題を解決する方法を教えてもらえますか?
私が使用したコード:
public class MyAlarmService extends IntentService {
public void onCreate() {
super.onCreate();
}
public MyAlarmService() {
super("MyAlarmService");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, startId, startId);
Toast.makeText(this, "MyAlarmService.onStart()", Toast.LENGTH_LONG).show();
return START_STICKY;
}
@SuppressWarnings("static-access")
@Override
protected void onHandleIntent(Intent intent) {
final Dialog alarmDialog = new Dialog(MyAlarmService.this);
alarmDialog .requestWindowFeature(alarmDialog.getWindow().FEATURE_NO_TITLE);
alarmDialog .getWindow().setBackgroundDrawable(new ColorDrawable(0));
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.clear_all_warning_dialog, (ViewGroup) findViewById(R.id.layout_warning_dialog));
TextView dialogTitile = (TextView) layout.findViewById(R.id.dialog_title_text);
TextView dialogDesc = (TextView) layout.findViewById(R.id.dialog_desc_text);
Button buttonYes = (Button) layout.findViewById(R.id.button_yes);
Button buttonNo = (Button) layout.findViewById(R.id.button_no);
alarmDialog.setContentView(layout);
alarmDialog.show();
buttonYes.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
alarmDialog.dismiss();
}
});
buttonNo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
alarmDialog.dismiss();
}
});
}
}