我有一个GridView,我有一个自定义适配器,它用自定义数据填充单元格,一些单元格有数据,其他单元格有列表。列表是动态创建的,并使用自定义列表适配器填充。
我希望在单击列表项后更新或刷新GridView内的所有内容,换句话说,更新/刷新需要在GridView的适配器内进行。
我该怎么做?
在点击了GridView内部列表中的某个项目后,我在适配器中使用了这个代码:
notifyDataSetChanged();
点击列表项后,应用程序崩溃了,我在错误日志中得到了这个:
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime FATAL EXCEPTION: main
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime java.lang.ClassCastException: android.widget.ListView
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at hnlapp.hairdresser.Adapter_Labels_GridView_Calendar_dayview.getView(Adapter_Labels_GridView_Calendar_dayview.java:428)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at android.widget.AbsListView.obtainView(AbsListView.java:1409)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at android.widget.GridView.makeAndAddView(GridView.java:1222)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at android.widget.GridView.makeRow(GridView.java:268)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at android.widget.GridView.fillSpecific(GridView.java:466)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at android.widget.GridView.layoutChildren(GridView.java:1125)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at android.widget.AbsListView.onLayout(AbsListView.java:1260)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at android.view.View.layout(View.java:7175)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1243)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at android.widget.LinearLayout.onLayout(LinearLayout.java:1049)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at android.os.Handler.dispatchMessage(Handler.java:99)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at android.os.Looper.loop(Looper.java:123)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at android.app.ActivityThread.main(ActivityThread.java:3683)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at java.lang.reflect.Method.invokeNative(Native Method)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at java.lang.reflect.Method.invoke(Method.java:507)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09:37:58.675 916 hnlapp.hairdresser ERROR AndroidRuntime at dalvik.system.NativeStart.main(Native Method)
09:38:05.195 60 system_process ERROR InputDispatcher channel '406e82a8 hnlapp.hairdresser/hnlapp.hairdresser.Page_Login (server)' ~ Consumer closed input channel or an error occurred. events=0x8
09:38:05.195 60 system_process ERROR InputDispatcher channel '406e82a8 hnlapp.hairdresser/hnlapp.hairdresser.Page_Login (server)' ~ Channel is unrecoverably broken and will be disposed!
该错误消息引用了我的getView方法中的这行代码:
Label = (TextView) convertView;
答案 0 :(得分:0)
只需调用适配器的notifyDataSetChanged
方法即可。
答案 1 :(得分:0)
尝试访问textview,如下所示:
Label = (TextView) convertView.findViewByID(R.id.textview);