从Github到现有的Android项目

从Github到现有的Android项目,android,github,android-widget,Android,Github,Android Widget,我是android开发新手,如果问题不清楚,很抱歉。 我想使用小部件“数字选择器”,它可以在Github上找到。我知道有一种方法可以将git项目导入eclipse,但我想做的是将它添加到已经存在的项目中。我已经尝试手动将类和所有包含的文件夹添加到我的项目的小部件中,问题是没有xml文件解释如何将这个数字选择器元素添加到活动中。 我是这样做的: 1.将Scroller和NumberPicker类添加到项目包下的src文件夹中。 2.添加了可绘制的XML、valuse和图像。 3.将jar文件添加到

我是android开发新手,如果问题不清楚,很抱歉。 我想使用小部件“数字选择器”,它可以在Github上找到。我知道有一种方法可以将git项目导入eclipse,但我想做的是将它添加到已经存在的项目中。我已经尝试手动将类和所有包含的文件夹添加到我的项目的小部件中,问题是没有xml文件解释如何将这个数字选择器元素添加到活动中。 我是这样做的: 1.将Scroller和NumberPicker类添加到项目包下的src文件夹中。 2.添加了可绘制的XML、valuse和图像。 3.将jar文件添加到Android Dependencies文件夹。 4.已将其添加到活动xml文件中:

<com.example.mathgame.NumberPicker
android:id="@+id/numberPicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
当我运行应用程序时,这是logCat中的例外:

12-14 20:23:26.283: E/AndroidRuntime(29792): FATAL EXCEPTION: main
12-14 20:23:26.283: E/AndroidRuntime(29792): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mathgame/com.example.mathgame.MainActivity}: java.lang.ClassCastException: android.widget.NumberPicker cannot be cast to com.example.mathgame.NumberPicker
我想知道wright使用导入的github项目的方式是什么,以及我应该如何修复这个项目。谢谢


我找到了应用程序崩溃的原因。由于使用了number_picker.xml文件,我在某些地方改为com.example.mathgame.NumberPicker。现在应用程序启动了,但是数字选择器看起来很奇怪(我有按钮和它附近的一些元素)。下面是它现在的样子:

<merge xmlns:android="http://schemas.android.com/apk/res/android">

    <ImageButton android:id="@+id/np_increment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="?attr/numberPickerUpButtonStyle"
        android:contentDescription="@string/np_number_picker_increment_button" />

    <view class="com.example.mathgame.NumberPicker$CustomEditText"
        android:id="@+id/np_numberpicker_input"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="?attr/numberPickerInputTextStyle" />

    <ImageButton android:id="@+id/np_decrement"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="?attr/numberPickerDownButtonStyle"
        android:contentDescription="@string/np_number_picker_decrement_button" />

</merge>

这是一个库项目。因此,您可以直接将此项目添加到android项目中。 只需导入一个库项目。 然后转到项目属性->安卓->向下滚动 添加库项目。
毕竟,将此库类用于创建对象。

chave您尝试过作为
com.example.mathgame.NumberPicker np=(com.example.mathgame.NumberPicke)findViewById(R.id.NumberPicker)如果您确定没有导入android.widget.NumberPicker在MainActivity中,尝试清理您的项目。我在几分钟后编辑了该问题fixes@VladIoffe:当前您如何将此项目添加到您的项目?@VladIoffe:首先从eclipse中的文件->导入操作导入工作区中的项目。然后右键单击您自己的项目并选择属性。从属性中选择Android选项,选择Android后会出现一个弹出窗口,在此窗口中向下滚动,您可以看到添加库选项。您能否解释如何将此库项目添加到我的项目中?转到项目属性->Android->向下滚动添加库项目
<merge xmlns:android="http://schemas.android.com/apk/res/android">

    <ImageButton android:id="@+id/np_increment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="?attr/numberPickerUpButtonStyle"
        android:contentDescription="@string/np_number_picker_increment_button" />

    <view class="com.example.mathgame.NumberPicker$CustomEditText"
        android:id="@+id/np_numberpicker_input"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="?attr/numberPickerInputTextStyle" />

    <ImageButton android:id="@+id/np_decrement"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="?attr/numberPickerDownButtonStyle"
        android:contentDescription="@string/np_number_picker_decrement_button" />

</merge>