Java Code Examples for androidx.recyclerview.widget.RecyclerView#setLayoutManager()
The following examples show how to use
androidx.recyclerview.widget.RecyclerView#setLayoutManager() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrinterBluetoothDialog.java From ProjectX with Apache License 2.0 | 6 votes |
PrinterBluetoothDialog(@NonNull Context context, @NonNull OnDialogListener listener) { super(context, AlertDialogUtils.getAlertDialogTheme(context)); mListener = listener; setContentView(R.layout.dlg_printer_bluetooth); final RecyclerView bonded = findViewById(R.id.dpb_rv_bonded); if (bonded == null) return; final Drawable divider = ContextCompat.getDrawable(context, R.drawable.divider_common); if (divider != null) { final DividerItemDecoration decoration = new DividerItemDecoration(context, DividerItemDecoration.VERTICAL); decoration.setDrawable(divider); bonded.addItemDecoration(decoration); } bonded.setLayoutManager(new LinearLayoutManager(context)); bonded.setAdapter(mAdapter); }
Example 2
Source File: MainActivity.java From storio with Apache License 2.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); storIOSQLite = DefaultStorIOSQLite.builder() .sqliteOpenHelper(new DbOpenHelper(this)) .addTypeMapping(Tweet.class, new TweetSQLiteTypeMapping()) .build(); tweetsAdapter = new TweetsAdapter(); recyclerView = (RecyclerView) findViewById(R.id.tweets_recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setAdapter(tweetsAdapter); addTweets(); }
Example 3
Source File: LicensesActivity.java From BonjourBrowser with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_license); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); mAdapter = new OpenSourceComponentAdapter(this, LICENSE_SOFTWARE, new String[]{ ANDROID_ASSETS_FILE_PATH + ANDROID_OPEN_SOURCE_PROJECT_LICENSE, ANDROID_ASSETS_FILE_PATH + ANDROID_OPEN_SOURCE_PROJECT_LICENSE, ANDROID_ASSETS_FILE_PATH + ANDROID_OPEN_SOURCE_PROJECT_LICENSE, ANDROID_ASSETS_FILE_PATH + ANDROID_SOFTWARE_DEVELOPMENT_KIT, ANDROID_ASSETS_FILE_PATH + APACHE_LICENSE, ANDROID_ASSETS_FILE_PATH + APACHE_LICENSE }); RecyclerView recyclerView = ((RecyclerView) findViewById(R.id.recycler_view)); recyclerView.setLayoutManager(mLayoutManager); recyclerView.setAdapter(mAdapter); }
Example 4
Source File: PropertiesBSFragment.java From indigenous-android with GNU General Public License v3.0 | 6 votes |
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); RecyclerView rvColor = view.findViewById(R.id.rvColors); SeekBar sbOpacity = view.findViewById(R.id.sbOpacity); SeekBar sbBrushSize = view.findViewById(R.id.sbSize); sbOpacity.setOnSeekBarChangeListener(this); sbBrushSize.setOnSeekBarChangeListener(this); LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false); rvColor.setLayoutManager(layoutManager); rvColor.setHasFixedSize(true); ColorPickerAdapter colorPickerAdapter = new ColorPickerAdapter(getActivity()); colorPickerAdapter.setOnColorPickerClickListener(new ColorPickerAdapter.OnColorPickerClickListener() { @Override public void onColorPickerClickListener(int colorCode) { if (mProperties != null) { dismiss(); mProperties.onColorChanged(colorCode); } } }); rvColor.setAdapter(colorPickerAdapter); }
Example 5
Source File: EmojiBSFragment.java From PhotoEditor with MIT License | 6 votes |
@SuppressLint("RestrictedApi") @Override public void setupDialog(Dialog dialog, int style) { super.setupDialog(dialog, style); View contentView = View.inflate(getContext(), R.layout.fragment_bottom_sticker_emoji_dialog, null); dialog.setContentView(contentView); CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams(); CoordinatorLayout.Behavior behavior = params.getBehavior(); if (behavior != null && behavior instanceof BottomSheetBehavior) { ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback); } ((View) contentView.getParent()).setBackgroundColor(getResources().getColor(android.R.color.transparent)); RecyclerView rvEmoji = contentView.findViewById(R.id.rvEmoji); GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 5); rvEmoji.setLayoutManager(gridLayoutManager); EmojiAdapter emojiAdapter = new EmojiAdapter(); rvEmoji.setAdapter(emojiAdapter); }
Example 6
Source File: SearchActivity.java From Ruisi with Apache License 2.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); mainWindow = findViewById(R.id.main_window); findViewById(R.id.btn_back).setOnClickListener(this); RecyclerView listView = findViewById(R.id.recycler_view); searchInput = findViewById(R.id.search_input); searchCard = findViewById(R.id.search_card); findViewById(R.id.start_search).setOnClickListener(this); findViewById(R.id.nav_search).setOnClickListener(this); searchInput.setHint("请输入搜索内容!"); adapter = new SimpleListAdapter(ListType.SERRCH, this, datas); RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this); listView.setLayoutManager(layoutManager); listView.addItemDecoration(new MyListDivider(this, MyListDivider.VERTICAL)); listView.addOnScrollListener(new LoadMoreListener((LinearLayoutManager) layoutManager, this, 20)); listView.setAdapter(adapter); adapter.changeLoadMoreState(BaseAdapter.STATE_LOAD_NOTHING); navTitle = findViewById(R.id.nav_title); findViewById(R.id.nav_back).setOnClickListener(this); searchInput.setOnEditorActionListener(this); }
Example 7
Source File: StandardHomeActivityUIController.java From commcare-android with Apache License 2.0 | 6 votes |
private void setupGridView() { final RecyclerView grid = activity.findViewById(R.id.home_gridview_buttons); grid.setHasFixedSize(false); StaggeredGridLayoutManager gridView = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL); grid.setLayoutManager(gridView); grid.setItemAnimator(null); grid.setAdapter(adapter); grid.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressLint("NewApi") @Override public void onGlobalLayout() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { grid.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { grid.getViewTreeObserver().removeOnGlobalLayoutListener(this); } grid.requestLayout(); adapter.notifyDataSetChanged(); activity.rebuildOptionsMenu(); } }); }
Example 8
Source File: VideoBrowserFragment.java From CastVideos-android with Apache License 2.0 | 5 votes |
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mRecyclerView = (RecyclerView) getView().findViewById(R.id.list); mEmptyView = getView().findViewById(R.id.empty_view); mLoadingView = getView().findViewById(R.id.progress_indicator); LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); mRecyclerView.setLayoutManager(layoutManager); mAdapter = new VideoListAdapter(this, getContext()); mRecyclerView.setAdapter(mAdapter); getLoaderManager().initLoader(0, null, this); }
Example 9
Source File: PuzzleSelectorActivity.java From EasyPhotos with Apache License 2.0 | 5 votes |
private void initPreview() { rvPreview = (RecyclerView) findViewById(R.id.rv_preview_selected_photos); LinearLayoutManager lm = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); previewAdapter = new PuzzleSelectorPreviewAdapter(this, selectedPhotos, this); rvPreview.setLayoutManager(lm); rvPreview.setAdapter(previewAdapter); }
Example 10
Source File: RecyclerViewFragment.java From CircleIndicator with Apache License 2.0 | 5 votes |
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { mAdapter = new SampleRecyclerAdapter(5); RecyclerView recyclerView = view.findViewById(R.id.recycler_view); LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false); recyclerView.setLayoutManager(layoutManager); recyclerView.setAdapter(mAdapter); PagerSnapHelper pagerSnapHelper = new PagerSnapHelper(); pagerSnapHelper.attachToRecyclerView(recyclerView); // CircleIndicator2 for RecyclerView CircleIndicator2 indicator = view.findViewById(R.id.indicator); indicator.attachToRecyclerView(recyclerView, pagerSnapHelper); // Scroll To Position layoutManager.scrollToPosition(2); // Observe Data Change mAdapter.registerAdapterDataObserver(indicator.getAdapterDataObserver()); view.findViewById(R.id.add).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mAdapter.add(); } }); view.findViewById(R.id.remove).setOnClickListener(v -> { mAdapter.remove(); }); }
Example 11
Source File: ExplodeAndEpicenterExample.java From Transitions-Everywhere with Apache License 2.0 | 5 votes |
@Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRecyclerView = new RecyclerView(container.getContext()); mRecyclerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); mRecyclerView.setLayoutManager(new GridLayoutManager(container.getContext(), 4)); mRecyclerView.setAdapter(new Adapter()); return mRecyclerView; }
Example 12
Source File: Example6Fragment.java From SectionedRecyclerViewAdapter with MIT License | 5 votes |
@Nullable @Override public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.fragment_ex6, container, false); sectionedAdapter = new SectionedRecyclerViewAdapter(); final LoadMoviesUseCase loadMoviesUseCase = new LoadMoviesUseCase(); sectionedAdapter.addSection(new ExpandableMovieSection(getString(R.string.top_rated_movies_topic), loadMoviesUseCase.execute(requireContext(), R.array.top_rated_movies), this)); sectionedAdapter.addSection(new ExpandableMovieSection(getString(R.string.most_popular_movies_topic), loadMoviesUseCase.execute(requireContext(), R.array.most_popular_movies), this)); final RecyclerView recyclerView = view.findViewById(R.id.recyclerview); final GridLayoutManager glm = new GridLayoutManager(getContext(), 2); glm.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(final int position) { if (sectionedAdapter.getSectionItemViewType(position) == SectionedRecyclerViewAdapter.VIEW_TYPE_HEADER) { return 2; } return 1; } }); recyclerView.setLayoutManager(glm); recyclerView.setAdapter(sectionedAdapter); return view; }
Example 13
Source File: ProductGridFragment.java From material-components-android-codelabs with Apache License 2.0 | 5 votes |
@Override public View onCreateView( @NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment with the ProductGrid theme View view = inflater.inflate(R.layout.shr_product_grid_fragment, container, false); // Set up the tool bar setUpToolbar(view); // Set up the RecyclerView RecyclerView recyclerView = view.findViewById(R.id.recycler_view); recyclerView.setHasFixedSize(true); GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 2, GridLayoutManager.HORIZONTAL, false); gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { return position % 3 == 2 ? 2 : 1; } }); recyclerView.setLayoutManager(gridLayoutManager); StaggeredProductCardRecyclerViewAdapter adapter = new StaggeredProductCardRecyclerViewAdapter( ProductEntry.initProductEntryList(getResources())); recyclerView.setAdapter(adapter); int largePadding = getResources().getDimensionPixelSize(R.dimen.shr_staggered_product_grid_spacing_large); int smallPadding = getResources().getDimensionPixelSize(R.dimen.shr_staggered_product_grid_spacing_small); recyclerView.addItemDecoration(new ProductGridItemDecoration(largePadding, smallPadding)); // Set cut corner background for API 23+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { view.findViewById(R.id.product_grid) .setBackgroundResource(R.drawable.shr_product_grid_background_shape); } return view; }
Example 14
Source File: EditObservationFragment.java From ground-android with Apache License 2.0 | 5 votes |
private void onShowPhotoSelectorDialog(Field field) { EditObservationBottomSheetBinding addPhotoBottomSheetBinding = EditObservationBottomSheetBinding.inflate(getLayoutInflater()); addPhotoBottomSheetBinding.setViewModel(viewModel); addPhotoBottomSheetBinding.setField(field); BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(getContext()); bottomSheetDialog.setContentView(addPhotoBottomSheetBinding.getRoot()); bottomSheetDialog.setCancelable(true); bottomSheetDialog.show(); AddPhotoDialogAdapter.ItemClickListener listener = type -> { bottomSheetDialog.dismiss(); switch (type) { case PHOTO_SOURCE_CAMERA: viewModel.showPhotoCapture(field); break; case PHOTO_SOURCE_STORAGE: viewModel.showPhotoSelector(field); break; default: throw new IllegalArgumentException("Unknown type: " + type); } }; RecyclerView recyclerView = addPhotoBottomSheetBinding.recyclerView; recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setAdapter(new AddPhotoDialogAdapter(listener)); }
Example 15
Source File: CharacteristicMappingsFragment.java From EFRConnect-android with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_characteristic_mappings, container, false); RecyclerView recyclerView = view.findViewById(R.id.recycler_view); MappingAdapter adapter = new MappingAdapter(list, getActivity(), MappingType.CHARACTERISTIC); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); recyclerView.setAdapter(adapter); // Inflate the layout for this fragment return view; }
Example 16
Source File: LibraryPreferenceDialog.java From Music-Player with GNU General Public License v3.0 | 5 votes |
@NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { View view = getActivity().getLayoutInflater().inflate(R.layout.preference_dialog_library_categories, null); List<CategoryInfo> categoryInfos; if (savedInstanceState != null) { categoryInfos = savedInstanceState.getParcelableArrayList(PreferenceUtil.LIBRARY_CATEGORIES); } else { categoryInfos = PreferenceUtil.getInstance(getContext()).getLibraryCategoryInfos(); } adapter = new CategoryInfoAdapter(categoryInfos); RecyclerView recyclerView = view.findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); recyclerView.setAdapter(adapter); adapter.attachToRecyclerView(recyclerView); return new MaterialDialog.Builder(getContext()) .title(R.string.library_categories) .customView(view, false) .positiveText(android.R.string.ok) .negativeText(android.R.string.cancel) .neutralText(R.string.reset_action) .autoDismiss(false) .onNeutral((dialog, action) -> adapter.setCategoryInfos(PreferenceUtil.getInstance(getContext()).getDefaultLibraryCategoryInfos())) .onNegative((dialog, action) -> dismiss()) .onPositive((dialog, action) -> { updateCategories(adapter.getCategoryInfos()); dismiss(); }) .build(); }
Example 17
Source File: ListActivity.java From ExoPlayer-Wrapper with Apache License 2.0 | 5 votes |
private void serRecyclerView() { RecyclerView recyclerView = findViewById(R.id.recyclerView); recyclerView.setLayoutManager(new SliderLayoutManager(this)); ArrayList<VideoItem> list = getVideoItemsList(); mAdapter = new RecyclerViewAdapter(list, mToolbar); getLifecycle().addObserver(mAdapter); recyclerView.setAdapter(mAdapter); }
Example 18
Source File: DemoAnimPTRActivity.java From smart-farmer-android with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_demo_anim_ptr); mPtrFrame = (PtrAnimFrameLayout) findViewById(R.id.ptr_frame); RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycle_view); //TODO TEST DATA Items allList = new Items(); for (int i = 0; i < 20; i++) { News news = new News(); news.setImgPath("http://img.d9soft.com/2016/0412/20160412032431842.png"); news.setTitle("新闻标题" + i); news.setDesc("新闻描述" + i); allList.add(news); } mAdapter = new MultiTypeAdapter(allList); mAdapter.register(News.class, new NewsViewBinder()); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setAdapter(mAdapter); mPtrFrame.postDelayed(new Runnable() { @Override public void run() { mPtrFrame.autoRefresh(); } }, 1000); mPtrFrame.setPtrHandler(new PtrDefaultHandler() { @Override public void onRefreshBegin(PtrFrameLayout frame) { ToastUtils.showShort("刷新了"); Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer<Long>() { @Override public void accept(Long aLong) { mPtrFrame.refreshComplete(); } }); } }); }
Example 19
Source File: SendConfirmActivity.java From green_android with GNU General Public License v3.0 | 4 votes |
private void setup() { // Setup views fields final TextView noteTextTitle = UI.find(this, R.id.sendMemoTitle); final TextView noteText = UI.find(this, R.id.noteText); final TextView addressText = UI.find(this, R.id.addressText); final JsonNode address = mTxJson.withArray("addressees").get(0); final String currentRecipient = address.get("address").asText(); final boolean isSweeping = mTxJson.get("is_sweep").asBoolean(); final Integer subaccount = mTxJson.get("subaccount").asInt(); UI.hideIf(isSweeping, noteTextTitle); UI.hideIf(isSweeping, noteText); addressText.setText(currentRecipient); noteText.setText(mTxJson.get("memo") == null ? "" : mTxJson.get("memo").asText()); CharInputFilter.setIfNecessary(noteText); // Set currency & amount final long amount = mTxJson.get("satoshi").asLong(); final long fee = mTxJson.get("fee").asLong(); final TextView sendAmount = UI.find(this, R.id.sendAmount); final TextView sendFee = UI.find(this, R.id.sendFee); final JsonNode assetTag = address.get("asset_tag"); if (getSession().getNetworkData().getLiquid()) { sendAmount.setVisibility(View.GONE); UI.find(this, R.id.amountWordSending).setVisibility(View.GONE); final String asset = assetTag.asText(); final Map<String, Long> balances = new HashMap<>(); balances.put(asset, address.get("satoshi").asLong()); final RecyclerView assetsList = findViewById(R.id.assetsList); assetsList.setLayoutManager(new LinearLayoutManager(this)); final AssetsAdapter adapter = new AssetsAdapter(balances, getNetwork(), null); assetsList.setAdapter(adapter); assetsList.setVisibility(View.VISIBLE); } else { sendAmount.setText(getFormatAmount(amount)); } sendFee.setText(getFormatAmount(fee)); if (mHwData != null && mTxJson.has("transaction_outputs")) { UI.show(UI.find(this, R.id.changeLayout)); final TextView view = UI.find(this, R.id.changeAddressText); final Collection<String> changesList = new ArrayList<>(); for (final JsonNode output : mTxJson.get("transaction_outputs")) { if (output.get("is_change").asBoolean() && !output.get("is_fee").asBoolean() && output.has("address")) { changesList.add("- " + output.get("address").asText()); } } view.setText(TextUtils.join("\n", changesList)); } mSwipeButton.setOnActiveListener(this); }
Example 20
Source File: DiscoverMoviesFragment.java From PopularMovies with MIT License | 4 votes |
private void setupListAdapter() { RecyclerView recyclerView = getActivity().findViewById(R.id.rv_movie_list); final DiscoverMoviesAdapter discoverMoviesAdapter = new DiscoverMoviesAdapter(viewModel); final GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), getResources().getInteger(R.integer.span_count)); // draw network status and errors messages to fit the whole row(3 spans) layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { switch (discoverMoviesAdapter.getItemViewType(position)) { case R.layout.item_network_state: return layoutManager.getSpanCount(); default: return 1; } } }); // setup recyclerView recyclerView.setAdapter(discoverMoviesAdapter); recyclerView.setLayoutManager(layoutManager); ItemOffsetDecoration itemDecoration = new ItemOffsetDecoration(getActivity(), R.dimen.item_offset); recyclerView.addItemDecoration(itemDecoration); // observe paged list viewModel.getPagedList().observe(getViewLifecycleOwner(), new Observer<PagedList<Movie>>() { @Override public void onChanged(PagedList<Movie> movies) { discoverMoviesAdapter.submitList(movies); } }); // observe network state viewModel.getNetworkState().observe(getViewLifecycleOwner(), new Observer<Resource>() { @Override public void onChanged(Resource resource) { discoverMoviesAdapter.setNetworkState(resource); } }); }