I am new to Android development. I want to create a customized date and time picker in my Application.
I downloaded this library from github to achieve this. When I try to use it in my application, it crashes and I got the following error:
java.lang.IllegalStateException: Activity has been destroyed
Can anybody look at my code to see what I am missing?
import jp.seesaa.android.datetimepicker.date.DatePickerDialog;
import jp.seesaa.android.datetimepicker.time.RadialPickerLayout;
import jp.seesaa.android.datetimepicker.time.TimePickerDialog;
/**
* Created by MAC12 on 20-Apr-15.
*/
public class HomeFragment extends Fragment implements DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener {
public HomeFragment(){
}
String tg="HomeFragment ";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
// cls.findViewById(R.layout.fragment_home).setOnClickListener();
return rootView;
}
@Override
public void onViewCreated(View view,Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
Button button = (Button) view.findViewById(R.id.date_picker_day);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ActivityCls cls=new ActivityCls();
cls.Start();
}
});
}
@Override
public void onDetach() {
super.onDetach();
try {
Field childFragmentManager = Fragment.class.getDeclaredField("fragment_home");
childFragmentManager.setAccessible(true);
childFragmentManager.set(this, null);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
public class ActivityCls extends FragmentActivity
{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// findViewById(R.layout.date_picker_day).setOnClickListener();
DatePickerDialog.newInstance(HomeFragment.this, 2006, 1, 2)
.show(getSupportFragmentManager(), "datepicker");
}
public void Start()
{
DatePickerDialog.newInstance(HomeFragment.this, 2006, 1, 2)
.show(getSupportFragmentManager(), "datepicker");
}
}
@Override
public void onStart() {
super.onStart();
}
@Override
public void onStop() {
// Log.w(TAG, "App stopped");
super.onStop();
}
@Override
public void onDestroy() {
// Log.w(TAG, "App destoryed");
super.onDestroy();
}
@Override
public void onDateSet(DatePickerDialog dialog, int year, int monthOfYear, int dayOfMonth) {
}
@Override
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) {
}
}
http://developer.android.com/guide/topics/ui/controls/pickers.html在这里,您可以看到日期的格式是飞蛾日和年,您要先输入年份然后再有例外。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.