本文整理匯總了Java中android.support.v7.widget.RecyclerView.postDelayed方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.postDelayed方法的具體用法?Java RecyclerView.postDelayed怎麽用?Java RecyclerView.postDelayed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.RecyclerView
的用法示例。
在下文中一共展示了RecyclerView.postDelayed方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initRecyclerWithIndicator
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void initRecyclerWithIndicator(int recyclerViewId, int indicatorViewId, final int itemCount, int delay) {
RecyclerView recyclerView = findViewById(recyclerViewId);
final OverflowPagerIndicator overflowPagerIndicator = findViewById(indicatorViewId);
final Adapter adapter = new Adapter();
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
recyclerView.setAdapter(adapter);
overflowPagerIndicator.attachToRecyclerView(recyclerView);
new SimpleSnapHelper(overflowPagerIndicator).attachToRecyclerView(recyclerView);
recyclerView.postDelayed(new Runnable() {
@Override
public void run() {
adapter.updateItemCount(itemCount);
}
}, delay);
}
示例2: disableLoadMoreIfNotFullPage
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* check if full page after {@link #setNewData(List)}, if full, it will enable load more again.
* <p>
* 不是配置項!!
* <p>
* 這個方法是用來檢查是否滿一屏的,所以隻推薦在 {@link #setNewData(List)} 之後使用
* 原理很簡單,先關閉 load more,檢查完了再決定是否開啟
* <p>
* 不是配置項!!
*
* @param recyclerView your recyclerView
* @see #setNewData(List)
*/
public void disableLoadMoreIfNotFullPage(RecyclerView recyclerView) {
setEnableLoadMore(false);
if (recyclerView == null) return;
RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
if (manager == null) return;
if (manager instanceof LinearLayoutManager) {
final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) manager;
recyclerView.postDelayed(new Runnable() {
@Override
public void run() {
if ((linearLayoutManager.findLastCompletelyVisibleItemPosition() + 1) != getItemCount()) {
setEnableLoadMore(true);
}
}
}, 50);
} else if (manager instanceof StaggeredGridLayoutManager) {
final StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) manager;
recyclerView.postDelayed(new Runnable() {
@Override
public void run() {
final int[] positions = new int[staggeredGridLayoutManager.getSpanCount()];
staggeredGridLayoutManager.findLastCompletelyVisibleItemPositions(positions);
int pos = getTheBiggestNumber(positions) + 1;
if (pos != getItemCount()) {
setEnableLoadMore(true);
}
}
}, 50);
}
}
示例3: disableLoadMoreIfNotFullPage
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* check if full page after {@link #setNewData(List)}, if full, it will enable load more again.
*
* @param recyclerView your recyclerView
* @see #setNewData(List)
*/
public void disableLoadMoreIfNotFullPage(RecyclerView recyclerView) {
setEnableLoadMore(false);
if (recyclerView == null) return;
RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
if (manager == null) return;
if (manager instanceof LinearLayoutManager) {
final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) manager;
recyclerView.postDelayed(new Runnable() {
@Override
public void run() {
if ((linearLayoutManager.findLastCompletelyVisibleItemPosition() + 1) != getItemCount()) {
setEnableLoadMore(true);
}
}
}, 50);
} else if (manager instanceof StaggeredGridLayoutManager) {
final StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) manager;
recyclerView.postDelayed(new Runnable() {
@Override
public void run() {
final int[] positions = new int[staggeredGridLayoutManager.getSpanCount()];
staggeredGridLayoutManager.findLastCompletelyVisibleItemPositions(positions);
int pos = getTheBiggestNumber(positions) + 1;
if (pos != getItemCount()) {
setEnableLoadMore(true);
}
}
}, 50);
}
}
示例4: disableLoadMoreIfNotFullPage
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* check if full page after {@link #setNewData(List)}, if full, it will enable load more again.
*
* @param recyclerView your recyclerView
* @see #setNewData(List)
*/
public void disableLoadMoreIfNotFullPage(RecyclerView recyclerView) {
if (recyclerView == null) return;
RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
if (manager == null) return;
if (manager instanceof LinearLayoutManager) {
final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) manager;
recyclerView.postDelayed(new Runnable() {
@Override
public void run() {
if ((linearLayoutManager.findLastCompletelyVisibleItemPosition() + 1) != getItemCount()) {
setEnableLoadMore(true);
}
}
}, 50);
} else if (manager instanceof StaggeredGridLayoutManager) {
final StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) manager;
recyclerView.postDelayed(new Runnable() {
@Override
public void run() {
final int[] positions = new int[staggeredGridLayoutManager.getSpanCount()];
staggeredGridLayoutManager.findLastCompletelyVisibleItemPositions(positions);
int pos = getTheBiggestNumber(positions) + 1;
if (pos != getItemCount()) {
setEnableLoadMore(true);
}
}
}, 50);
}
}
示例5: initializeRecyclerView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@SuppressWarnings({"ConstantConditions", "NullableProblems"})
private void initializeRecyclerView(Bundle savedInstanceState) {
//Get copy of the Database list
List<AbstractFlexibleItem> items = DatabaseService.getInstance().getDatabaseList();
// Initialize Adapter and RecyclerView
// ExampleAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()'
mAdapter = new ExampleAdapter(items, getActivity());
mAdapter.setNotifyChangeOfUnfilteredItems(true) //This will rebind new item when refreshed
.setMode(SelectableAdapter.MODE_SINGLE);
// Experimenting NEW features (v5.0.0)
mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(createNewLinearLayoutManager());
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setHasFixedSize(true); //Size of RV will not change
// NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if
// a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange.
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
// Divider item decorator with DrawOver enabled
mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), R.drawable.divider)
.withDrawOver(true));
mRecyclerView.postDelayed(new Runnable() {
@Override
public void run() {
Snackbar.make(getView(), "Selection MODE_SINGLE is enabled", Snackbar.LENGTH_SHORT).show();
}
}, 1500L);
// Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!!
mAdapter.setFastScroller((FastScroller) getView().findViewById(R.id.fast_scroller),
Utils.getColorAccent(getActivity()), (MainActivity) getActivity());
SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setEnabled(true);
mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, SelectableAdapter.MODE_SINGLE);
// Add 2 Scrollable Headers
mAdapter.addUserLearnedSelection(savedInstanceState == null);
mAdapter.addScrollableHeaderWithDelay(new ScrollableUseCaseItem(
getString(R.string.selection_modes_use_case_title),
getString(R.string.selection_modes_use_case_description)), 1100L, true
);
}
示例6: initializeRecyclerView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@SuppressWarnings({"ConstantConditions", "NullableProblems"})
private void initializeRecyclerView(Bundle savedInstanceState) {
// Initialize Adapter and RecyclerView
// OverallAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()'
// In this example the Adapter make uses of METHOD B and extends FlexibleAdapter: items
// don't implement the AutoMap and don't implement create and binding methods: The Adapter
// remains responsible to handling all view types.
mAdapter = new OverallAdapter(getActivity());
// Experimenting NEW features (v5.0.0)
mAdapter.setOnlyEntryAnimation(true)
.setAnimationInterpolator(new DecelerateInterpolator())
.setAnimationInitialDelay(500L)
.setAnimationDelay(70L);
// Prepare the RecyclerView and attach the Adapter to it
mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
mRecyclerView.setItemViewCacheSize(0); //Setting ViewCache to 0 (default=2) will animate items better while scrolling down+up with LinearLayout
mRecyclerView.setLayoutManager(createNewStaggeredGridLayoutManager());
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setHasFixedSize(true); //Size of RV will not change
// After Adapter is attached to RecyclerView
mAdapter.setLongPressDragEnabled(true);
mRecyclerView.postDelayed(new Runnable() {
@Override
public void run() {
if (getView() != null) { //Fix NPE when closing app before the execution of Runnable
Snackbar.make(getView(), "Long press drag is enabled", Snackbar.LENGTH_SHORT).show();
}
}
}, 4000L);
SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setEnabled(true);
mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, SelectableAdapter.MODE_IDLE);
// Add 2 Scrollable Headers
mAdapter.showLayoutInfo(savedInstanceState == null);
mAdapter.addScrollableHeader(new ScrollableUseCaseItem(
getString(R.string.overall_use_case_title),
getString(R.string.overall_use_case_description)));
}