-1
這是我在java.class上的代碼 我的日期選擇器運行平穩,但在時間選擇器,這是CUSTOMIZED間隔30是保持無法添加的錯誤窗口?我該怎麼辦?任何幫助將是一個很大的幫助....我只是在Android新手....我的timepicker沒有運行,logcat錯誤說BADTOKENEXCEPTION無法添加窗口
public class loansched_accountholder extends Activity implements OnClickListener
{
JSONParser jsonParser = new JSONParser();
private Button change_date_but,proceed;
private TextView display_txt;
public static final int Date_dialog_id = 1;
private int mYear;
private int mMonth;
private int mDay;
private TextView txt_time = null;
private Button btn_time = null;
private static final String TAG_MESSAGE = "message";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.schedule_accountholder, null);
this.setContentView(viewToLoad);
change_date_but = (Button) findViewById(R.id.btndate);
display_txt = (TextView) findViewById(R.id.tvdate);
proceed = (Button) findViewById(R.id.proceedsched);
txt_time = (TextView) findViewById(R.id.tvtime);
btn_time = (Button) findViewById(R.id.buttonSelectTime);
change_date_but.setOnClickListener(this);
proceed.setOnClickListener(this);
btn_time.setOnClickListener(this);
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
updateDisplay();
}
@Override
@Deprecated
protected void onPrepareDialog(int id, Dialog dialog) {
// TODO Auto-generated method stub
super.onPrepareDialog(id, dialog);
((DatePickerDialog) dialog).updateDate(mYear, mMonth, mDay);
}
private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
updateDisplay();
}
};
private void updateDisplay() {
// TODO Auto-generated method stub
display_txt.setText(new StringBuilder()
.append(mMonth + 1).append("-").append(mDay).append("-")
.append(mYear));
}
protected Dialog onCreateDialog(int id) {
switch (id) {
case Date_dialog_id:
return new DatePickerDialog(MainAccountHolder.tabcontext, mDateSetListener, mYear, mMonth, mDay);
}
return null;
}
protected void onPostExecute(String file_url) {
if (file_url != null){
Toast.makeText(loansched_accountholder.this, file_url, Toast.LENGTH_LONG).show();
}
}
}
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.proceedsched:
try{
new postLoan_info().execute();
}catch(Exception ex)
{
ex.printStackTrace();
}
break;
case R.id.btndate:
showDialog(Date_dialog_id);
break;
case R.id.buttonSelectTime:
try
{
CustomTimePickerDialog timePickerDialog = new CustomTimePickerDialog(loansched_accountholder.this, timeSetListener,
Calendar.getInstance().get(Calendar.HOUR),
CustomTimePickerDialog.getRoundedMinute(Calendar.getInstance().get(Calendar.MINUTE) + CustomTimePickerDialog.TIME_PICKER_INTERVAL), true);
timePickerDialog.setTitle("Set your appointment time");
timePickerDialog.show();
}catch(Exception ex)
{
ex.printStackTrace();
}
break;
}
}
public static class CustomTimePickerDialog extends TimePickerDialog{
public static final int TIME_PICKER_INTERVAL=30;
private boolean mIgnoreEvent=false;
public CustomTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) {
super(context, callBack, hourOfDay, minute, is24HourView);
}
@Override
public void onTimeChanged(TimePicker timePicker, int hourOfDay, int minute) {
super.onTimeChanged(timePicker, hourOfDay, minute);
if (!mIgnoreEvent){
minute = getRoundedMinute(minute);
mIgnoreEvent=true;
timePicker.setCurrentMinute(minute);
mIgnoreEvent=false;
}
}
public static int getRoundedMinute(int minute){
if(minute % TIME_PICKER_INTERVAL != 0){
int minuteFloor = minute - (minute % TIME_PICKER_INTERVAL);
minute = minuteFloor + (minute == minuteFloor + 1 ? TIME_PICKER_INTERVAL : 0);
if (minute == 60) minute=0;
}
return minute;
}
}
private CustomTimePickerDialog.OnTimeSetListener timeSetListener = new CustomTimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
txt_time.setText(String.format("%02d", hourOfDay) + ":" +String.format("%02d", minute));
}
};
}
,這是我的logcat
02-19 12:51:27.707: W/System.err(1757): android.view.WindowManager$BadTokenException: Unable to add window -- token [email protected] is not valid; is your activity running?
02-19 12:51:27.707: W/System.err(1757): at android.view.ViewRootImpl.setView(ViewRootImpl.java:559)
02-19 12:51:27.717: W/System.err(1757): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:269)
02-19 12:51:27.717: W/System.err(1757): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
02-19 12:51:27.717: W/System.err(1757): at android.app.Dialog.show(Dialog.java:281)
02-19 12:51:27.717: W/System.err(1757): at com.example.mobilebankingapp.loansched_accountholder.onClick(loansched_accountholder.java:371)
02-19 12:51:27.717: W/System.err(1757): at android.view.View.performClick(View.java:4240)
02-19 12:51:27.727: W/System.err(1757): at android.view.View$PerformClick.run(View.java:17721)
02-19 12:51:27.727: W/System.err(1757): at android.os.Handler.handleCallback(Handler.java:730)
02-19 12:51:27.727: W/System.err(1757): at android.os.Handler.dispatchMessage(Handler.java:92)
02-19 12:51:27.737: W/System.err(1757): at android.os.Looper.loop(Looper.java:137)
02-19 12:51:27.737: W/System.err(1757): at android.app.ActivityThread.main(ActivityThread.java:5103)
02-19 12:51:27.737: W/System.err(1757): at java.lang.reflect.Method.invokeNative(Native Method)
02-19 12:51:27.747: W/System.err(1757): at java.lang.reflect.Method.invoke(Method.java:525)
02-19 12:51:27.747: W/System.err(1757): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
02-19 12:51:27.747: W/System.err(1757): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-19 12:51:27.747: W/System.err(1757): at dalvik.system.NativeStart.main(Native Method)
這是我的應用程序感謝那些誰可以幫助我出於此...
謝謝...但postLoan_info()是太多的代碼行,所以我沒有添加它......但它確實影響,即使我沒有單擊posloan_info()按鈕? – user3329399
如何解決?這裏同樣的問題 –