自定义类的小吃店未显示 [英] Snackbar from custom class not showing

查看:121
本文介绍了自定义类的小吃店未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MyActivity coord.xml:

MyActivity coord.xml:

<CoordinatorLayout>
   id:coordID
   <RelativeL>
      ...
   <FAB>

RVAdapter.java

RVAdapter.java

...
@Override
    public void onItemDismiss(int position) {
        ...
        notifyItemRemoved(position);

        LayoutInflater inflater = (LayoutInflater) MyActivity.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflater.inflate(R.layout.coord, null);

        Snackbar.make(v.findViewById(R.id.coordID), "TEXT", Snackbar.LENGTH_LONG).show();
    }

这是一种在自定义类(RVAdapter.java)中刷卡从回收者视图列表中删除项目的方法,删除后,应显示Snackbar并为UNDO设置操作.但是,当我删除项目时,什么也没发生.小吃店没有出现.我不确定我是否可以正确设置视图,但是我不知道该怎么做

This is a method for swiping to delete an item from recycler view list, in a custom class (RVAdapter.java) and after its deleted, Snackbar should appear and set action for UNDO. But, when I delete an item, nothing happends. Snackbar doesnt show up. Im not so sure if I set views correctly, but I dont know how to do it differently

推荐答案

感谢MikeM.我这样解决了它:
在MyActivity中添加

Thx to Mike M. I solved it like this:
In MyActivity added

private static CoordinatorLayout mCoord;
mCoord = findViewById(R.id.coordID);
public static View getCoord() { return mCoord; }

和RVAdapter.java

and in RVAdapter.java

Snackbar.make(MyActivity.getCoord(), ...

这篇关于自定义类的小吃店未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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