因此,我正在编写代码以从时间选择器中选择时间a并将此文本添加到edittextprefrence中,由于某种原因,我无法执行此操作。
这是我的代码,用于将时间选择器中的时间添加到edittextprefrence
public class extra extends PreferenceActivity {
//private SharedPreferences.OnSharedPreferenceChangeListener listener;
private EditTextPreference from;
private EditTextPreference to;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.extra);
final timeSelector ts = new timeSelector();
from =(EditTextPreference) findPreference("camera-service-time_from");
//to = (EditTextPreference) findPreference("camera-service-time_to") ;
from.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
String put = ts.timeSel();
Log.d("TEST2:",put);
from.setText(put);
setPreferenceScreen(null);
addPreferencesFromResource(R.xml.extra);
return false;
}
});
}
我的时间选择器代码:
public class timeSelector
{
int pickdhr;
int pickdmin;
String timeSel()
{
//here
Calendar c = Calendar.getInstance();
int mHour = c.get(Calendar.HOUR_OF_DAY);
int mMinute = c.get(Calendar.MINUTE);
TimePickerDialog timePickerDialog = new TimePickerDialog(extra.this,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {
pickdhr= hourOfDay;
pickdmin= minute;
}
}, mHour, mMinute, true);
timePickerDialog.show();
Log.d("TEST3:",pickdhr+":"+pickdmin);
return pickdhr+":"+ pickdmin;
}
}
}
因此,我无法将所选时间添加到出现错误的edittextprefrence中?