1
我創建了時間選擇器。但是在我的項目中,我需要在EditText字段中插入四個時間選擇器。當點擊EditText時,它會提示theililog設置時間。它很長,以便在Activity類中創建時間選擇器。所以我想創建一個單獨的時間選擇器類。我創建了TimePickerClass,但它顯示錯誤。 請幫幫我。如何創建一個單獨的時間選擇器類
package com.sample.uiscreen;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.view.View;
import android.widget.EditText;
import android.widget.TimePicker;
public class TimePickClass {
private int mHour;
private int mMinute;
EditText time;
public static final int TIME_DIALOG_ID = 0;
MyActivity ma=null;
// the callback received when the user "sets" the time in the dialog
public TimePickerDialog.OnTimeSetListener mTimeSetListener =
new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mHour = hourOfDay;
mMinute = minute;
time.setText(
new StringBuilder()
.append(pad(mHour)).append(":")
.append(pad(mMinute)));}
//pad method
private String pad(int c) {
if (c >= 10)
return String.valueOf(c);
else return "0" + String.valueOf(c); } };
protected Dialog onCreateDialog(int id) {
switch (id) {
case TIME_DIALOG_ID:
return new TimePickerDialog(ma,
mTimeSetListener, mHour, mMinute, true); }
return null; }
}
什麼錯誤?棧跟蹤請... – Mudassir 2011-02-28 05:55:07
我得到解決方案如何創建多個時間picker.But我創建這些在Activity類。但我想在一個新的類。 – 2011-02-28 06:43:13