如何刷新ChildItems上的ExpandableBaseAdapter已更改

时间:2017-08-03 05:30:30

标签: android xamarin.android expandablelistview expandablelistadapter

我有以下部分GroupExpand事件的代码,我想开始意向服务并通知广播接收器上更改的数据集。我能够获得广播接收器的刷新数据集OnReceive()方法,但attendanceExpListAdapter.NotifyDataSetChanged()对我来说不起作用。

AttendanceExpandableListFragment.Cs

      public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
..........
 // create new adapter at first and set it
        attendanceExpListAdapter = new AttendanceExpandableListAdapter(this.Context, classSectionAttendanceList);
        expListView.SetAdapter(attendanceExpListAdapter);

        expListView.GroupExpand += ExpListView_GroupExpand;
 return rootView;
       }

 private void ExpListView_GroupClick(object sender, ExpandableListView.GroupClickEventArgs e)
    {
        //Showing loading progressbar
        progress.Visibility = ViewStates.Visible;
        DA_ClassSectionAttendance classSectionAttendanceItem = classSectionAttendanceList.ElementAt(e.GroupPosition);


        // start attendencae intent service
        // run Academic Calendar Intent Service
        Intent attendanceIntent = new Intent(this.Context, typeof(AttendanceService));

        // This is just one example of passing some values to an IntentService via the Intent:
        attendanceIntent.PutExtra(AttendanceConstant.KEY_CLASS, classSectionAttendanceItem.ClassId);
        attendanceIntent.PutExtra(AttendanceConstant.KEY_SECTION, classSectionAttendanceItem.SectionId);

        this.Context.StartService(attendanceIntent);
        Log.Debug(Tag, "test:attendance service started");
    }

广播接收器的一部分

 private void NotifyAdapterDatasetChanged()
        {
            try
            {
                if (attendanceExpListAdapter == null)
                    return;
                if(!attendanceExpListAdapter.IsEmpty)
                {
                    attendanceExpListAdapter.NotifyDataSetChanged();                       
                }


            }catch(Java.Lang.Exception e)
            {

            }
        }

每当我点击Group Item时,我会先得到一个新的AttendanceExpandableListAdapter(this.Context,classSectionAttendanceList),其中包含先前的数据集,但不会更新已插入子项的更新。

而且,首先,当我第一次创建AttendanceExpandableListFragment视图时,我得到一个空白屏幕,第二次我得到组视图。

示例代码非常感谢。

谢谢。

0 个答案:

没有答案