Java Code Examples for android.support.v7.widget.RecyclerView#setLayoutManager()

The following examples show how to use android.support.v7.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: RecyclerViewActivity.java    From CommonAdapter with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mRecyclerView = new RecyclerView(this);
    LayoutUtil.setContentView(this, mRecyclerView);

    LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    layoutManager.setRecycleChildrenOnDetach(true);
    mRecyclerView.setLayoutManager(layoutManager);

    // 放一个默认空数据
    mRecyclerView.setAdapter(getAdapter(null));

    // 现在得到数据
    final List<DemoModel> data = DataManager.loadData(getBaseContext());
    ((IAdapter<DemoModel>) mRecyclerView.getAdapter()).setData(data); // 设置新的数据
    mRecyclerView.getAdapter().notifyDataSetChanged(); // 通知数据刷新

    loadNewData(data);
}
 
Example 2
Source File: NewFriendPresenter.java    From Android with MIT License 6 votes vote down vote up
@Override
public void initGrid(RecyclerView recycler) {
    ArrayList<WalletMenuBean> menuList = new ArrayList<>();
    menuList.add(new WalletMenuBean(R.mipmap.contract_add_scan3x, R.string.Link_Scan));
    menuList.add(new WalletMenuBean(R.mipmap.contract_add_contacts3x, R.string.Link_Contacts));
    menuList.add(new WalletMenuBean(R.mipmap.contract_add_more3x, R.string.Link_More));

    WalletMenuAdapter walletMenuAdapter = new WalletMenuAdapter(menuList, mView.getActivity());
    recycler.setLayoutManager(new GridLayoutManager(mView.getActivity(), 3));
    recycler.setAdapter(walletMenuAdapter);
    walletMenuAdapter.setOnItemClickListence(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int tag = (Integer) v.getTag();
            mView.itemClick(tag);
        }
    });
}
 
Example 3
Source File: TopFragment.java    From HeadFirstAndroid with MIT License 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    RelativeLayout layout = (RelativeLayout)inflater.inflate(R.layout.fragment_top, container, false);
    RecyclerView pizzaRecycler = (RecyclerView)layout.findViewById(R.id.pizza_recycler);
    String[] pizzaNames = new String[2];
    for (int i = 0; i < 2; i++) {
        pizzaNames[i] = Pizza.pizzas[i].getName();
    }
    int[] pizzaImages = new int[2];
    for (int i = 0; i < 2; i++) {
        pizzaImages[i] = Pizza.pizzas[i].getImageResourceId();
    }
    GridLayoutManager layoutManager = new GridLayoutManager(getActivity(),2);
    pizzaRecycler.setLayoutManager(layoutManager);
    CaptionedImagesAdapter adapter = new CaptionedImagesAdapter(pizzaNames, pizzaImages);
    pizzaRecycler.setAdapter(adapter);
    adapter.setListener(new CaptionedImagesAdapter.Listener() {
            public void onClick(int position) {
                Intent intent = new Intent(getActivity(), PizzaDetailActivity.class);
                intent.putExtra(PizzaDetailActivity.EXTRA_PIZZANO, position);
                getActivity().startActivity(intent);
            }
        });
    return layout;
}
 
Example 4
Source File: MainActivity.java    From LiveSourceCode with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    findViewById(R.id.btn_request).setOnClickListener(onClickListener);
    findViewById(R.id.btn_select_image).setOnClickListener(onClickListener);
    mTvResult = (TextView) findViewById(R.id.tv_result);
    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            outRect.set(5, 5, 5, 5);
        }
    });
    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));

    int size = measureSize();
    mAdapter = new AlbumPreviewAdapter(this, size);
    mRecyclerView.setAdapter(mAdapter);
}
 
Example 5
Source File: RegisterPresenterImpl.java    From Saude-no-Mapa with MIT License 6 votes vote down vote up
private void setupBottomSheetDialog() {
    mBottomSheetDialog = new BottomSheetDialog(mContext);
    View dialogView = LayoutInflater.from(mContext)
            .inflate(R.layout.dialog_bottom_sheet_profile, null);

    RecyclerView avatarRecycler = (RecyclerView) dialogView.findViewById(R.id.avatar_recycler);
    avatarRecycler.setHasFixedSize(true);
    avatarRecycler.setLayoutManager(new GridLayoutManager(mContext, 3, GridLayoutManager.VERTICAL, false));

    avatarRecycler.setAdapter(new AvatarAdapter(mContext, this));

    mBottomSheetDialog.setContentView(dialogView);

    dialogView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

    BottomSheetBehavior mBehavior = BottomSheetBehavior.from((View) dialogView.getParent());
    mBehavior.setPeekHeight(dialogView.getMeasuredHeight() + 200);

    mBottomSheetDialog.show();
}
 
Example 6
Source File: EventActivity.java    From Hillffair17 with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    SharedPref pref= new SharedPref(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_event);
    Toolbar toolbar= (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    progressBar= (ProgressBar) findViewById(R.id.progress);
    adapter=new ClubEventAdapter(this);
    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(new GridLayoutManager(this,2));
    recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, new RecyclerItemClickListener.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            Intent i=new Intent(EventActivity.this,ClubActivity.class);
            i.putExtra(CLUB_ID,list.get(position).getId());
            startActivity(i);
        }
    }));
    showData();
}
 
Example 7
Source File: ListContentFragment.java    From android-design-library with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    RecyclerView recyclerView = (RecyclerView) inflater.inflate(
            R.layout.recycler_view, container, false);
    ContentAdapter adapter = new ContentAdapter(recyclerView.getContext());
    recyclerView.setAdapter(adapter);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    return recyclerView;
}
 
Example 8
Source File: WeatherForecastViewHolder.java    From your-local-weather with GNU General Public License v3.0 5 votes vote down vote up
public WeatherForecastViewHolder(View itemView,
                                 Context context,
                                 Set<Integer> visibleColumns) {
    super(itemView);
    mContext = context;
    this.visibleColumns = visibleColumns;

    mDate = (TextView) itemView.findViewById(R.id.forecast_date);
    headerTime = (TextView) itemView.findViewById(R.id.forecast_header_time);
    headerIcon = (TextView) itemView.findViewById(R.id.forecast_header_icon);
    headerDescription = (TextView) itemView.findViewById(R.id.forecast_header_description);
    headerTemperature = (TextView) itemView.findViewById(R.id.forecast_header_temperature);
    headerApparentTemperature = (TextView) itemView.findViewById(R.id.forecast_header_apparent_temperature);
    headerWind = (TextView) itemView.findViewById(R.id.forecast_header_wind);
    headerWindDirection = (TextView) itemView.findViewById(R.id.forecast_header_wind_direction);
    headerRainSnow = (TextView) itemView.findViewById(R.id.forecast_header_rainsnow);
    headerHumidity = (TextView) itemView.findViewById(R.id.forecast_header_humidity);
    headerPressure = (TextView) itemView.findViewById(R.id.forecast_header_presure);

    headerTimeUnit = (TextView) itemView.findViewById(R.id.forecast_header_time_unit);
    headerIconUnit = (TextView) itemView.findViewById(R.id.forecast_header_icon_unit);
    headerDescriptionUnit = (TextView) itemView.findViewById(R.id.forecast_header_description_unit);
    headerTemperatureUnit = (TextView) itemView.findViewById(R.id.forecast_header_temperature_unit);
    headerApparentTemperatureUnit = (TextView) itemView.findViewById(R.id.forecast_header_apparent_temperature_unit);
    headerWindUnit = (TextView) itemView.findViewById(R.id.forecast_header_wind_unit);
    headerWindDirectionUnit = (TextView) itemView.findViewById(R.id.forecast_header_wind_direction_unit);
    headerRainSnowUnit = (TextView) itemView.findViewById(R.id.forecast_header_rainsnow_unit);
    headerHumidityUnit = (TextView) itemView.findViewById(R.id.forecast_header_humidity_unit);
    headerPressureUnit = (TextView) itemView.findViewById(R.id.forecast_header_presure_unit);

    mRecyclerView = (RecyclerView) itemView.findViewById(R.id.forecast_recycler_view_item);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
}
 
Example 9
Source File: ExampleListActivity.java    From UILibrary with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_example_list);

    mExampleItemList = new ArrayList<>();
    mAdapter = new ExampleListAdapter(mExampleItemList);

    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
}
 
Example 10
Source File: FontActivity.java    From GreatFit with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    RecyclerView root = new RecyclerView(this);
    //Add header to a list of settings
    List<BaseSetting> settings = new ArrayList<>();
    settings.add(new HeaderSetting(getString(R.string.set_font)));
    //Setup items for each day
    String[] fonts = ResourceManager.getNames(ResourceManager.Font.class);//getResources().getStringArray(R.array.colors);
    final SharedPreferences sharedPreferences = getSharedPreferences(getPackageName()+"_settings", Context.MODE_PRIVATE);
    int x = 0;
    int current = sharedPreferences.getInt("font", 0);
    for(String font : fonts){
        //Each item needs a Setting
        final int finalX = x;
        settings.add(new IconSetting( (current==x)?getDrawable(R.drawable.check):getDrawable(R.drawable.circle_icon), font, null, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sharedPreferences.edit().putInt("font", finalX).apply();
                FontActivity.this.finish();
            }
        }, x));
        x++;
    }
    //Setup layout
    root.setBackgroundResource(R.drawable.settings_background);
    root.setLayoutManager(new LinearLayoutManager(this));
    root.setAdapter(new Adapter(this, settings));
    root.setPadding((int) getResources().getDimension(R.dimen.padding_round_small), 0, (int) getResources().getDimension(R.dimen.padding_round_small), (int) getResources().getDimension(R.dimen.padding_round_large));
    root.setClipToPadding(false);
    setContentView(root);
}
 
Example 11
Source File: BaseMainActivity.java    From LRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mRecyclerView = (RecyclerView) findViewById(R.id.list);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    mDataList = new ArrayList<>();
    for (int i = 0; i < getActivitys().length; i++) {

        ListItem item = new ListItem();
        item.title = getTitles()[i];
        item.activity = getActivitys()[i];
        mDataList.add(item);
    }

    mDataAdapter = new DataAdapter(this);
    mDataAdapter.setData(mDataList);
    mRecyclerView.setAdapter(mDataAdapter);

    DividerDecoration divider = new DividerDecoration.Builder(this)
            .setColorResource(R.color.divider)
            .build();
    mRecyclerView.addItemDecoration(divider);


}
 
Example 12
Source File: VideoEditActivity.java    From PLDroidShortVideo with Apache License 2.0 5 votes vote down vote up
private void initFiltersList() {
    mFiltersList = (RecyclerView) findViewById(R.id.recycler_view);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    mFiltersList.setLayoutManager(layoutManager);
    mFiltersList.setAdapter(new FilterListAdapter(mShortVideoEditor.getBuiltinFilterList()));
    setPanelVisibility(mFiltersList, true);
}
 
Example 13
Source File: RecyView.java    From AndroidHeros with MIT License 5 votes vote down vote up
public void init(Context context) {

        mRcList = new RecyclerView(context);
        mLayoutManager = new LinearLayoutManager(context);
        mRcList.setLayoutManager(mLayoutManager);
        mRcList.setHasFixedSize(true);
        // 设置显示动画
        mRcList.setItemAnimator(new DefaultItemAnimator());
        // 增加测试数据
        mAdapter = new RecyclerAdapter(mData);
        mRcList.setAdapter(mAdapter);
        this.addView(mRcList);
    }
 
Example 14
Source File: SelectPhotosActivity.java    From Expert-Android-Programming with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_select_photos);

    item = (BucketItem) getIntent().getSerializableExtra(Constant.DATA);
    allSelected = DaoController.getPhotoItems(context);

    title = (TextView) findViewById(R.id.title);

    allList = new ArrayList<>();
    adapter = new BucketPhotoAdapter(context, allList);
    adapter.setClickListener(new BucketPhotoAdapter.ClickListener() {
        @Override
        public void onItemClickListener(View v, int pos) {

            boolean b = allList.get(pos).isSelected();
            allList.get(pos).setSelected(!b);
            adapter.refresh(allList, pos);

            countSelected();

        }
    });

    recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    recyclerView.setNestedScrollingEnabled(false);
    recyclerView.setLayoutManager(new GridLayoutManager(context, 3));
    recyclerView.setAdapter(adapter);

    marshmallowPermission = new MarshmallowPermission(this);

    title.setText(item.getName());

    checkPermissions();
}
 
Example 15
Source File: EditActivity.java    From In77Camera with MIT License 5 votes vote down vote up
private void setFilterList() {
    glRootView= (GLRootView) findViewById(R.id.camera_view);
    glWrapper= GLWrapper.newInstance()
            .setGlImageView(glRootView)
            .setContext(this)
            .init();

    FileUtils.upZipFile(this,"filter/thumbs/thumbs.zip",getFilesDir().getAbsolutePath());

    filterListView= (RecyclerView) findViewById(com.martin.ads.omoshiroilib.R.id.filter_list);

    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    filterListView.setLayoutManager(linearLayoutManager);

    List<FilterType> filterTypeList=new ArrayList<>();
    for(int i = 0; i< FilterType.values().length; i++){
        filterTypeList.add(FilterType.values()[i]);
        if(i==0) filterTypeList.add(FilterType.NONE);
    }
    FilterAdapter filterAdapter=new FilterAdapter(this,filterTypeList);
    filterListView.setAdapter(filterAdapter);
    filterAdapter.setOnFilterChangeListener(new FilterAdapter.OnFilterChangeListener() {
        @Override
        public void onFilterChanged(FilterType filterType) {
            glWrapper.switchLastFilterOfCustomizedFilters(filterType);
        }
    });
}
 
Example 16
Source File: RecyclerViewUtils.java    From UGank with GNU General Public License v3.0 5 votes vote down vote up
public static void setVerticalLinearLayout(RecyclerView rv) {
    LinearLayoutManager layoutManager = new LinearLayoutManager(rv.getContext(), LinearLayoutManager.VERTICAL, false) {
        @Override
        public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
            try {
                super.onLayoutChildren(recycler, state);
            } catch (IndexOutOfBoundsException e) {
                Log.e(TAG, "meet an IndexOutOfBoundsException in RecyclerView");
            }
        }
    };
    rv.setLayoutManager(layoutManager);
}
 
Example 17
Source File: EventListActivity.java    From android-samples with Apache License 2.0 5 votes vote down vote up
private void setRecyclerView() {
    RecyclerView eventList = (RecyclerView) findViewById(R.id.event_list);
    eventList.setItemAnimator(new DefaultItemAnimator());
    eventList.setLayoutManager(new LinearLayoutManager(this));

    RecyclerView.ItemDecoration dividerItemDecoration = new DividerItemDecorator(ContextCompat.getDrawable(this, R.drawable.line_divider));
    eventList.addItemDecoration(dividerItemDecoration);

    eventList.setAdapter(new RecyclerViewAdapter(getCalenderEvents()));
}
 
Example 18
Source File: CheeseListFragment.java    From RecyclerViewPager with Apache License 2.0 4 votes vote down vote up
private void setupRecyclerView(RecyclerView recyclerView) {
    recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
    recyclerView.setAdapter(new SimpleStringRecyclerViewAdapter(getActivity(),
            getRandomSublist(Cheeses.sCheeseStrings, 30)));
}
 
Example 19
Source File: AlbumDetailFragment.java    From Muzesto with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(21)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(
            R.layout.fragment_album_detail, container, false);

    albumArt = (ImageView) rootView.findViewById(R.id.album_art);
    artistArt = (ImageView) rootView.findViewById(R.id.artist_art);
    albumTitle = (TextView) rootView.findViewById(R.id.album_title);
    albumDetails = (TextView) rootView.findViewById(R.id.album_details);

    toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);

    fab = (FloatingActionButton) rootView.findViewById(R.id.fab);

    if (getArguments().getBoolean("transition")) {
        albumArt.setTransitionName(getArguments().getString("transition_name"));
    }
    recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview);
    collapsingToolbarLayout = (CollapsingToolbarLayout) rootView.findViewById(R.id.collapsing_toolbar);
    appBarLayout = (AppBarLayout) rootView.findViewById(R.id.app_bar);
    recyclerView.setEnabled(false);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    album = AlbumLoader.getAlbum(getActivity(), albumID);

    setAlbumart();

    setUpEverything();


    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    AlbumSongsAdapter adapter = (AlbumSongsAdapter) recyclerView.getAdapter();
                    MusicPlayer.playAll(getActivity(), adapter.getSongIds(), 0, albumID, TimberUtils.IdType.Album, true);
                    NavigationUtils.navigateToNowplaying(getActivity(), false);
                }
            }, 150);
        }
    });

    return rootView;
}
 
Example 20
Source File: ExpandListDemoActivity.java    From expandable-recyclerview with MIT License 3 votes vote down vote up
private void vertical(RecyclerView recyclerView) {
    recyclerView.setLayoutManager(new LinearLayoutManager(this));

    adapter = new VExpandableAdapter(shopList);
    recyclerView.setAdapter(adapter);

}