0

我有一个 GridView,我有一个自定义适配器,可以用自定义数据填充单元格,一些单元格有数据,而其他单元格有列表。列表是动态创建的,并使用自定义列表适配器填充。

单击列表项后,我想更新或刷新 GridView 内的所有内容,因此换句话说,更新/刷新需要在 GridView 的适配器内进行。

我该怎么做?

编辑#1

在我单击 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;  
4

2 回答 2

0

尝试访问 textview 如下:

Label = (TextView) convertView.findViewByID(R.id.textview);  
于 2013-01-29T07:31:53.477 回答
0

只需调用notifyDataSetChanged适配器的方法。

于 2013-01-29T07:19:17.900 回答