如何从适配器刷新主活动中的视图? [英] How to refresh a view in main activity from an adapter?

查看:149
本文介绍了如何从适配器刷新主活动中的视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主要活动中有一个图表,在主要活动中也有一个回收站视图。自定义适配器用于recyclerview。我有一个复选框,并在列表项布局中滑动了布局。在滑动布局中有一个删除按钮。

I have a graph in main activity also I have a recycler view in main activity. Custom adapter is used for recyclerview. I have a check box and swipe layout in list item layout. in swipe layout there is a delete button.

我想在选中复选框或删除任何项目时重置主要活动的图形。

I want to reset the graph of main activity when I check the check box or when I delete any item.

为此,我在主活动中创建了一个方法。并在适配器onCheckedChangeListener和单击删除时调用此方法。

For this I created one method in main activity. And called this method in adapter onCheckedChangeListener and on click of delete.

但是我在mBarChart上得到了一个空指针异常。即图形。我已经在setUI方法的mBarChart中实例化了,在活动的onCreate中调用了它。

But I am getting a null pointer exception on mBarChart. i.e . graph. I have instantiated in mBarChart in setUI method and this is called in onCreate of an activity.

resetMethod

resetMethod

    public void resetGraph(Context context)
{

    mBarChart.invalidate();

}

在适配器中:

  Context conext;
  MainActivity mainActivity;

  mainActivity = new MainActivity();

  mainActivity.resetGraph(conext);

该怎么做?请帮助。.谢谢..

How to do this? Please help.. Thank you..

推荐答案

在Adapter中以这种方式调用您的resetMethod

In Adapter call your resetMethod this way

((MainActivity)context).resetGraph(context);

这篇关于如何从适配器刷新主活动中的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆