我是Android的新手,我正在使用http://code.google.com/p/android-dateslider/组件,我想将其添加到我的视图中而不是弹出对话框中。
这意味着我将在视图顶部设置对话框滑块,通过滑动它将会显示下面选定日期的其他信息。
有没有办法做到这一点,或者我只能使用对话框表格。 (我知道对于datepicker我可以在视图中使用xml声明位置,但我真的很喜欢使用datespinner,因为它非常棒:))
编辑://
我通过以下方式通过xml声明尝试了它:
<com.googlecode.android.widgets.DateSlider.SliderContainer
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/dateSliderContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/button1">
<com.googlecode.android.widgets.DateSlider.ScrollLayout
style="@style/Scroller"
app:childWidth="90dp"
app:labelerClass="com.googlecode.android.widgets.DateSlider.labeler.MonthYearLabeler"
app:labelerFormat="%tb %tY" >
</com.googlecode.android.widgets.DateSlider.ScrollLayout>
<com.googlecode.android.widgets.DateSlider.ScrollLayout
style="@style/Scroller"
app:childWidth="45dp"
app:labelerClass="com.googlecode.android.widgets.DateSlider.labeler.DayDateLabeler"
app:labelerFormat="%td %ta" >
</com.googlecode.android.widgets.DateSlider.ScrollLayout>
<include layout="@layout/dialogbuttons" />
</com.googlecode.android.widgets.DateSlider.SliderContainer>
当我启动应用程序时,我可以看到日期滑动,但是当我触摸它时,应用程序崩溃:应用程序已经意外停止。抛出此异常:
10-05 20:04:59.995: E/AndroidRuntime(428): FATAL EXCEPTION: main
10-05 20:04:59.995: E/AndroidRuntime(428): java.lang.NullPointerException
10-05 20:04:59.995: E/AndroidRuntime(428): at com.googlecode.android.widgets.DateSlider.SliderContainer$1.onScroll(SliderContainer.java:38)
10-05 20:04:59.995: E/AndroidRuntime(428): at com.googlecode.android.widgets.DateSlider.ScrollLayout.reScrollTo(ScrollLayout.java:402)
10-05 20:04:59.995: E/AndroidRuntime(428): at com.googlecode.android.widgets.DateSlider.ScrollLayout.onTouchEvent(ScrollLayout.java:488)
10-05 20:04:59.995: E/AndroidRuntime(428): at android.view.View.dispatchTouchEvent(View.java:3885)
10-05 20:04:59.995: E/AndroidRuntime(428): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:903)
10-05 20:04:59.995: E/AndroidRuntime(428): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
10-05 20:04:59.995: E/AndroidRuntime(428): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
10-05 20:04:59.995: E/AndroidRuntime(428): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
10-05 20:04:59.995: E/AndroidRuntime(428): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
10-05 20:04:59.995: E/AndroidRuntime(428): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
10-05 20:04:59.995: E/AndroidRuntime(428): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1691)
10-05 20:04:59.995: E/AndroidRuntime(428): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1125)
10-05 20:04:59.995: E/AndroidRuntime(428): at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
10-05 20:04:59.995: E/AndroidRuntime(428): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675)
10-05 20:04:59.995: E/AndroidRuntime(428): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194)
10-05 20:04:59.995: E/AndroidRuntime(428): at android.view.ViewRoot.handleMessage(ViewRoot.java:1878)
10-05 20:04:59.995: E/AndroidRuntime(428): at android.os.Handler.dispatchMessage(Handler.java:99)
10-05 20:04:59.995: E/AndroidRuntime(428): at android.os.Looper.loop(Looper.java:130)
10-05 20:04:59.995: E/AndroidRuntime(428): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-05 20:04:59.995: E/AndroidRuntime(428): at java.lang.reflect.Method.invokeNative(Native Method)
10-05 20:04:59.995: E/AndroidRuntime(428): at java.lang.reflect.Method.invoke(Method.java:507)
10-05 20:04:59.995: E/AndroidRuntime(428): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-05 20:04:59.995: E/AndroidRuntime(428): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-05 20:04:59.995: E/AndroidRuntime(428): at dalvik.system.NativeStart.main(Native Method)
所以我想应该创建SliderContainer实例......但是在哪里?