actionListener not called with snackbar attached to ViewGroup.
pawelantczak opened this issue · 5 comments
Hello.
Like in titie.
Regards.
Hi. Could you provide more detail of this issue?
I am trying to reproduce this issue with the "Show in Dialog" sample which attaches snackbar to RelativeLayout, but actionListener called properly though.
Hello.
My approach was this:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mRootView = inflater.inflate(R.layout.fragment_main, container, false);
ButterKnife.inject(this, mRootView);
SnackbarManager.show(Snackbar.with(mActivity)
.text("Text")
.actionLabel("Label")
.actionListener(this)
.duration(Snackbar.SnackbarDuration.LENGTH_SHORT)
.eventListener(this), container);
}
Can't reproduce. However, I'm using a bit different code which uses onViewCreated()
method because snackbar won't appear when the SnackbarManager.show()
method invoked in onCreateView()
.
public class TestFragmentActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_empty);
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceHolderFragment())
.commit();
}
public static class PlaceHolderFragment extends Fragment implements ActionClickListener, EventListener {
private View mRootView;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mRootView = inflater.inflate(R.layout.fragment_dialog_list, container, false);
ButterKnife.inject(this, mRootView);
return mRootView;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
SnackbarManager.show(Snackbar.with(getActivity())
.text("Text")
.actionLabel("Label")
.actionListener(this)
.duration(Snackbar.SnackbarDuration.LENGTH_SHORT)
.eventListener(this), (ViewGroup) mRootView.getParent());
}
@Override
public void onActionClicked(Snackbar snackbar) {
}
@Override
public void onShow(Snackbar snackbar) {
}
@Override
public void onShowByReplace(Snackbar snackbar) {
}
@Override
public void onShown(Snackbar snackbar) {
}
@Override
public void onDismiss(Snackbar snackbar) {
}
@Override
public void onDismissByReplace(Snackbar snackbar) {
}
@Override
public void onDismissed(Snackbar snackbar) {
}
}
}
I was able to reproduce this issue with a viewgroup after dismiss and show again the snackbar. Do you have an idea why this occurs?
@AndreRoss Okay, reproduced. But I think that is not the same issue of which @pawelantczak has reported.
Are you reusing the same instance of Snackbar
class, right? I think current implementation does not consider to reuse the same instance in spite of attaching to Activity or ViewGroup. You should create a new Snackbar
instance each time for now.
ref.) Reusing same snackbar instance #23