我正在使用parallax scroll,当项目是文本时运行正常。然后,我希望列表的第0项是ImageView,所以我在if(groupPosition ==0 )
中添加了一个条件getGroupView()
,它按预期工作,然后我想在imageview下放置一个微调器,所以我添加了一个第二个条件if(groupPosition ==1 )
在滚动期间给我这个例外。我的所有代码都是相同的
10-22 22:52:23.459: E/InputEventReceiver(31336): Exception dispatching input event.
10-22 22:52:23.469: E/MessageQueue-JNI(31336): Exception in MessageQueue callback: handleReceiveCallback
10-22 22:52:23.499: E/MessageQueue-JNI(31336): java.lang.ClassCastException: android.widget.Spinner cannot be cast to android.widget.TextView
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at com.vivekwarde.chalisaaartistutisangraha.CustomExpandableListAdapter.getGroupView(CustomExpandableListAdapter.java:150)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:446)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.widget.AbsListView.obtainView(AbsListView.java:2260)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.widget.ListView.makeAndAddView(ListView.java:1769)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.widget.ListView.fillDown(ListView.java:672)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.widget.ListView.fillGap(ListView.java:636)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5045)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3202)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.widget.AbsListView.onTouchEvent(AbsListView.java:3476)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.View.dispatchTouchEvent(View.java:7127)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2170)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1905)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1934)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1388)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.app.Activity.dispatchTouchEvent(Activity.java:2396)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1882)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.View.dispatchPointerEvent(View.java:7307)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3174)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3119)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4157)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4136)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4228)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.os.MessageQueue.nativePollOnce(Native Method)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.os.MessageQueue.next(MessageQueue.java:125)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.os.Looper.loop(Looper.java:124)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at android.app.ActivityThread.main(ActivityThread.java:4794)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at java.lang.reflect.Method.invokeNative(Native Method)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at java.lang.reflect.Method.invoke(Method.java:511)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
10-22 22:52:23.499: E/MessageQueue-JNI(31336): at dalvik.system.NativeStart.main(Native Method)
10-22 22:52:23.499: W/dalvikvm(31336): threadid=1: thread exiting with uncaught exception (group=0x40bdf450)
10-22 22:52:23.509: E/AndroidRuntime(31336): FATAL EXCEPTION: main
10-22 22:52:23.509: E/AndroidRuntime(31336): java.lang.ClassCastException: android.widget.Spinner cannot be cast to android.widget.TextView
10-22 22:52:23.509: E/AndroidRuntime(31336): at com.vivekwarde.chalisaaartistutisangraha.CustomExpandableListAdapter.getGroupView(CustomExpandableListAdapter.java:150)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:446)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.widget.AbsListView.obtainView(AbsListView.java:2260)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.widget.ListView.makeAndAddView(ListView.java:1769)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.widget.ListView.fillDown(ListView.java:672)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.widget.ListView.fillGap(ListView.java:636)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5045)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3202)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.widget.AbsListView.onTouchEvent(AbsListView.java:3476)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.View.dispatchTouchEvent(View.java:7127)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2170)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1905)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
10-22 22:52:23.509: E/AndroidRuntime(31336): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1934)
10-22 22:52:23.509: E/AndroidRuntime(31336): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1388)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.app.Activity.dispatchTouchEvent(Activity.java:2396)
10-22 22:52:23.509: E/AndroidRuntime(31336): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1882)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.View.dispatchPointerEvent(View.java:7307)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3174)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3119)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4157)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4136)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4228)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.os.MessageQueue.nativePollOnce(Native Method)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.os.MessageQueue.next(MessageQueue.java:125)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.os.Looper.loop(Looper.java:124)
10-22 22:52:23.509: E/AndroidRuntime(31336): at android.app.ActivityThread.main(ActivityThread.java:4794)
10-22 22:52:23.509: E/AndroidRuntime(31336): at java.lang.reflect.Method.invokeNative(Native Method)
10-22 22:52:23.509: E/AndroidRuntime(31336): at java.lang.reflect.Method.invoke(Method.java:511)
10-22 22:52:23.509: E/AndroidRuntime(31336): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
10-22 22:52:23.509: E/AndroidRuntime(31336): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
10-22 22:52:23.509: E/AndroidRuntime(31336): at dalvik.system.NativeStart.main(Native Method)
这是代码,我不知道导致问题的原因
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if(groupPosition ==0 )
{ ImageView imageView = (ImageView) convertView;
if (imageView == null)
imageView = (ImageView) inflater.inflate(R.layout.image_big, null);
//imageView.setImageDrawable();
return imageView;
}
if(groupPosition==1)
{
Spinner spinner = (Spinner) convertView;
if (spinner == null)
spinner = (Spinner) inflater.inflate(R.layout.spinner, null);
//imageView.setImageDrawable();
List<String> list = new ArrayList<String>();
list.add("Android");
list.add("Java");
list.add("Spinner Data");
list.add("Spinner Adapter");
list.add("Spinner Example");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>
(myContext, android.R.layout.simple_spinner_item,list);
dataAdapter.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);
return spinner;
}
else
{
TextView textView = (TextView) convertView;// line 150 : exception after scrolling when spinner view is gone
if (textView == null)
textView = (TextView) inflater.inflate(R.layout.item, null);
textView.setText(getGroup(groupPosition));
return textView;
}
}
Spinner.xml
<?xml version="1.0" encoding="utf-8"?>
<Spinner xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:prompt="@string/spinner_prompt" >
</Spinner>
我从最近1小时开始尝试,但不知道如何解决它。
帮助!!
提前致谢...
答案 0 :(得分:0)
java.lang.ClassCastException: android.widget.Spinner cannot be cast to android.widget.TextView
问题在于您将convertView
转换为TextView
!,TextView
Spinner.xml
TextView textView = (TextView) convertView;// line 150 : exception after scrolling when spinner view is gone