Open kientux opened 9 years ago
Oh, very sorry, I just read README again and realized that I can set it using
app:recyclerviewFloatingActionView="@layout/custom_fab_view"
in layout file.
But I still hope there's a method for programmatically use :)
I reopen this because I can't find a "proper" way to setOnClickListener
on each FloatingActionButton
.
I'm currently using this:
FloatingActionsMenu floatMenu = (FloatingActionsMenu) ultimateRecyclerView.getCustomFloatingActionView();
for (int i = 0; i < floatMenu.getChildCount(); i++) {
FloatingActionButton button = (FloatingActionButton) floatMenu.getChildAt(i);
switch (button.getId()) {
case R.id.buttonOne:
button.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "ONE PRESSED", Toast.LENGTH_SHORT).show();
}
});
break;
case R.id.buttonTwo:
button.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "TWO PRESSED", Toast.LENGTH_SHORT).show();
}
});
break;
case R.id.buttonThree:
button.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "THREE PRESSED", Toast.LENGTH_SHORT).show();
}
});
break;
default:
break;
}
}
which is a pretty bad way? Is there any easier way to do this? I tried extend FloatingActionsMenu
, inflate custom view, set onclick in there, and use that custom class in layout. But it throws a bunch of runtime exception when runs.
I really want to know how to setup a single floating button on the URV. Would you like to post some more sample code if u got some time. @kientux @cymcsg
@jjhesk
You should see in the example app. To add a button or a menu, you must create a layout custom_fab_view
(or whatever name), then add this attribute:
app:recyclerviewFloatingActionView="@layout/custom_fab_view"
to recyclerview in xml, and call recyclerView.showFloatingButtonView()
.
<com.marshalchen.ultimaterecyclerview.UltimateRecyclerView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/recycler_view"
app:recyclerviewClipToPadding="true"
app:recyclerviewFloatingActionView="@layout/custom_fab_view"
app:recyclerviewScrollbars="vertical"
app:recyclerviewEmptyView="@layout/empty_view"
app:recyclerviewDefaultSwipeColor="@array/google_colors"
android:layout_marginTop="?attr/actionBarSize" />
If you add this scrollview callback, you will make it works with scrollable view, or else it will be static:
recyclerView.setScrollViewCallbacks(new ObservableScrollViewCallbacks() {
@Override
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
}
@Override
public void onDownMotionEvent() {
}
@Override
public void onUpOrCancelMotionEvent(ObservableScrollState observableScrollState) {
if (observableScrollState == ObservableScrollState.UP) {
recyclerView.hideFloatingActionMenu();
} else if (observableScrollState == ObservableScrollState.DOWN) {
recyclerView.showFloatingActionMenu();
}
}
});
For how to create custom_fab_view
, see floating_view.xml
in example app.
But when I just set one FAB with the URV, it can't follow the scroll behavior, although I have try setScrollViewCallbacks to hide and show. Any solution?
I want to create my own
FloatingActionsMenu
, but there's no way to set it to recycler view. The only method issetDefaultFloatingActionButton
, but it is for one button. This method is commented out in library code:Maybe you should add a public method to set
mFloatingButtonView
ormFloatingButtonViewStub
?