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

The following examples show how to use android.support.v7.widget.RecyclerView#setAdapter() . 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: MainActivity.java    From OkDownload 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);

    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rv);

    DownloadRvAdapter adapter = new DownloadRvAdapter(this);
    LinearLayoutManager manager = new LinearLayoutManager(this);

    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(manager);
    recyclerView.setAdapter(adapter);
}
 
Example 2
Source File: MainActivity.java    From mentions with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * After typing some text with mentions in the comment box and clicking on send, you will
 * be able to see the comment with the mentions highlighted above the comment box. This method
 * setups the adapter for this list.
 */
private void setupCommentsList() {
    final RecyclerView commentsList = ViewUtils.findViewById(this, R.id.comments_list);
    commentsList.setLayoutManager(new LinearLayoutManager(this));
    commentsAdapter = new CommentsAdapter(this);
    commentsList.setAdapter(commentsAdapter);

    // setup send button
    sendCommentButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (StringUtils.isNotBlank(commentField.getText())) {
                ViewUtils.hideView(MainActivity.this, R.id.comments_empty_view);

                // add comment to list
                final Comment comment = new Comment();
                comment.setComment(commentField.getText().toString());
                comment.setMentions(mentions.getInsertedMentions());
                commentsAdapter.add(comment);

                // clear comment field
                commentField.setText("");
            }
        }
    });
}
 
Example 3
Source File: HandleAdapterActivity.java    From FancyAdapters with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recycler_view_nopadding);

    List<String> items = new ArrayList<>();
    for (int i = 0; i < 30; i++) {
        items.add("Item " + i);
    }

    recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
    adapter = new CustomAdapter(items, recyclerView);
    adapter.setSelectableViewBehavior(SelectableViewAdapter.SelectableViewBehavior.RESPOND_TO_CLICK_EVENTS);
    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(getBaseContext()));

}
 
Example 4
Source File: Sponsor.java    From mConference-Framework with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view =  inflater.inflate(R.layout.fragment_sponsor, container, false);

    // boolean webPageprovided = false;

    RecyclerView sponsorRecyclerView = (RecyclerView) view.findViewById(R.id.sponsor_recycler_view);
    sponsorRecyclerView.setHasFixedSize(true);
    sponsorRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    Database db = new Database(view.getContext());
    ArrayList<SponsorDetails> sponsors = db.getSponsors();

    SponsorRecyclerView sponsorAdapter = new SponsorRecyclerView(sponsors);
    sponsorRecyclerView.setAdapter(sponsorAdapter);

    return view;
}
 
Example 5
Source File: TileContentFragment.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);
    // Set padding for Tiles
    int tilePadding = getResources().getDimensionPixelSize(R.dimen.tile_padding);
    recyclerView.setPadding(tilePadding, tilePadding, tilePadding, tilePadding);
    recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
    return recyclerView;
}
 
Example 6
Source File: SearchActivity.java    From Hands-Chopping with Apache License 2.0 5 votes vote down vote up
@Override
public void initData(@Nullable Bundle savedInstanceState) {
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    swipeRefreshLayout=(SwipeRefreshLayout)findViewById(R.id.swipeRefreshLayout);

    swipeRefreshLayout.setEnabled(false);
    recyclerView=(RecyclerView)findViewById(R.id.recyclerView);
    LinearLayoutManager llm = new LinearLayoutManager(this);
    llm.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(llm);
    recyclerView.setAdapter(mAdapter);

}
 
Example 7
Source File: BaseListFragment.java    From VideoMeeting with Apache License 2.0 5 votes vote down vote up
public void setRecyclerView(RecyclerView recyclerView, ArrayAdapter<T> adapter) {
    this.recyclerView = recyclerView;
    if (recyclerView.getLayoutManager() == null) {
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
    }
    bindLoadMoreListener(recyclerView);
    recyclerView.setAdapter(adapter);
    setAdapter(adapter);
}
 
Example 8
Source File: RecyclerViewVideoActivity.java    From TigerVideo with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.recyclerview_layout);
    mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview);

    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.setAdapter(new VideoAdapter(this));
}
 
Example 9
Source File: PreferenceEditorDialog.java    From DataInspector with Apache License 2.0 5 votes vote down vote up
@Override public void onAttachedToWindow() {
  super.onAttachedToWindow();

  File prefsDir = new File("/data/data/" + context.getPackageName() + "/shared_prefs");
  String[] prefs = prefsDir.list();

  Spinner spinner = (Spinner) findViewById(R.id.spinner);
  RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
  final WrapLinearLayoutManager layoutManager =
      new WrapLinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
  layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
  recyclerView.setLayoutManager(layoutManager);

  if (prefs != null) {
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
        | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
        | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

    for (int i = 0; i < prefs.length; i++) prefs[i] = prefs[i].split("\\.")[0];
    spinnerAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, prefs);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    PreferenceListAdapter listAdapter = new PreferenceListAdapter(context);
    recyclerView.setAdapter(listAdapter);
    spinner.setAdapter(spinnerAdapter);
    RxAdapterView.itemSelections(spinner).map(new Func1<Integer, String>() {
      @Override public String call(Integer position) {
        return spinnerAdapter.getItem(position).split("\\.")[0];
      }
    }).subscribe(listAdapter);
  } else {
    spinner.setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_spinner_item,
        new String[] { "No Prefs Found" }));
  }
}
 
Example 10
Source File: RecyclerViewSimpleActivity.java    From StickHeaderLayout with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recyclerview);

    RecyclerView v_scroll = (RecyclerView)findViewById(R.id.v_scroll);

    LinearLayoutManager mLayoutMgr = new LinearLayoutManager(this);
    v_scroll.setLayoutManager(mLayoutMgr);

    RecyclerAdapter recyclerAdapter = new RecyclerAdapter();
    recyclerAdapter.addItems(createItemList());
    v_scroll.setAdapter(recyclerAdapter);
}
 
Example 11
Source File: frag2.java    From EasyTabs with MIT License 5 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    rv = (RecyclerView) view.findViewById(R.id.rv);
    items = new ArrayList<>();
    adapter = new VideoAdapter(view.getContext(), items);
    llm = new LinearLayoutManager(view.getContext());
    rv.setLayoutManager(llm);
    rv.setAdapter(adapter);
    for (int i = 0; i <= 150; i++){
        items.add(new VideoItem(String.valueOf(i), String.valueOf(i), String.valueOf(i)));
    }

}
 
Example 12
Source File: MainActivity.java    From GraphView with Apache License 2.0 5 votes vote down vote up
private void setupRecyclerView() {
    RecyclerView graphs = findViewById(R.id.graphs);
    graphs.setLayoutManager(new LinearLayoutManager(this));
    graphs.setAdapter(new GraphListAdapter());
    DividerItemDecoration decoration = new DividerItemDecoration(getApplicationContext(), VERTICAL);
    graphs.addItemDecoration(decoration);
}
 
Example 13
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 14
Source File: ChatActivity.java    From bridgefy-android-samples with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);
    ButterKnife.bind(this);

    // recover our Peer object
    conversationName = getIntent().getStringExtra(INTENT_EXTRA_NAME);
    conversationId   = getIntent().getStringExtra(INTENT_EXTRA_UUID);

    // Configure the Toolbar
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // Enable the Up button
    ActionBar ab = getSupportActionBar();
    if (ab != null) {
        ab.setTitle(conversationName);
        ab.setDisplayHomeAsUpEnabled(true);
    }

    // register the receiver to listen for incoming messages
    LocalBroadcastManager.getInstance(getBaseContext())
            .registerReceiver(new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    Message message = new Message(intent.getStringExtra(MainActivity.INTENT_EXTRA_MSG));
                    message.setDeviceName(intent.getStringExtra(MainActivity.INTENT_EXTRA_NAME));
                    message.setDirection(Message.INCOMING_MESSAGE);
                    messagesAdapter.addMessage(message);
                }
            }, new IntentFilter(conversationId));

    // configure the recyclerview
    RecyclerView messagesRecyclerView = findViewById(R.id.message_list);
    LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager(this);
    mLinearLayoutManager.setReverseLayout(true);
    messagesRecyclerView.setLayoutManager(mLinearLayoutManager);
    messagesRecyclerView.setAdapter(messagesAdapter);
}
 
Example 15
Source File: HotListViewHolder.java    From LRecyclerView with Apache License 2.0 5 votes vote down vote up
public HotListViewHolder(View itemView) {
    super(itemView);
    recyclerView = (RecyclerView) itemView.findViewById(R.id.recycler_view);
    LinearLayoutManager layoutManager
            = new LinearLayoutManager(itemView.getContext(), LinearLayoutManager.HORIZONTAL, false);
    layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    recyclerView.setLayoutManager(layoutManager);
    adapter = new HotsAdapter();
    recyclerView.setAdapter(adapter);
}
 
Example 16
Source File: Test3Activity.java    From YCStateLayout with Apache License 2.0 5 votes vote down vote up
private void initRecycleView() {
    recyclerView = (RecyclerView) findViewById(R.id.recycleView);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    adapter = new MainAdapter(lists,this);
    recyclerView.setAdapter(adapter);
    adapter.setOnItemClickListener(new HhItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            if(lists.size()>position && position>-1){
                Toast.makeText(Test3Activity.this,"条目"+position+"被点击呢",Toast.LENGTH_SHORT).show();
            }
        }
    });
    showContent();
}
 
Example 17
Source File: HalfRightSwipeFragment.java    From swipe-maker with Apache License 2.0 5 votes vote down vote up
private void initRecyclerView(View view) {
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.swipe_list);
    recyclerView.setHasFixedSize(true);
    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
    recyclerView.setLayoutManager(layoutManager);
    mAdapter = new HalfRightSwipeAdapter(Album.getAlbum());
    mAdapter.setOnItemDismissListener(this);
    mAdapter.setOnItemItemSelectListener(this);
    recyclerView.setAdapter(mAdapter);
}
 
Example 18
Source File: BaseActivity.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
protected void setDummyData(RecyclerView recyclerView, int num) {
    recyclerView.setAdapter(new SimpleRecyclerAdapter(this, getDummyData(num)));
}
 
Example 19
Source File: MainActivity.java    From android-dev-challenge with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_forecast);

    /*
     * Using findViewById, we get a reference to our RecyclerView from xml. This allows us to
     * do things like set the adapter of the RecyclerView and toggle the visibility.
     */
    mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview_forecast);

    /* This TextView is used to display errors and will be hidden if there are no errors */
    mErrorMessageDisplay = (TextView) findViewById(R.id.tv_error_message_display);

    /*
     * A LinearLayoutManager is responsible for measuring and positioning item views within a
     * RecyclerView into a linear list. This means that it can produce either a horizontal or
     * vertical list depending on which parameter you pass in to the LinearLayoutManager
     * constructor. In our case, we want a vertical list, so we pass in the constant from the
     * LinearLayoutManager class for vertical lists, LinearLayoutManager.VERTICAL.
     *
     * There are other LayoutManagers available to display your data in uniform grids,
     * staggered grids, and more! See the developer documentation for more details.
     */
    int recyclerViewOrientation = LinearLayoutManager.VERTICAL;

    /*
     *  This value should be true if you want to reverse your layout. Generally, this is only
     *  true with horizontal lists that need to support a right-to-left layout.
     */
    boolean shouldReverseLayout = false;
    LinearLayoutManager layoutManager
            = new LinearLayoutManager(this, recyclerViewOrientation, shouldReverseLayout);
    mRecyclerView.setLayoutManager(layoutManager);

    /*
     * Use this setting to improve performance if you know that changes in content do not
     * change the child layout size in the RecyclerView
     */
    mRecyclerView.setHasFixedSize(true);

    /*
     * The ForecastAdapter is responsible for linking our weather data with the Views that
     * will end up displaying our weather data.
     */
    mForecastAdapter = new ForecastAdapter(this);

    /* Setting the adapter attaches it to the RecyclerView in our layout. */
    mRecyclerView.setAdapter(mForecastAdapter);

    /*
     * The ProgressBar that will indicate to the user that we are loading data. It will be
     * hidden when no data is loading.
     *
     * Please note: This so called "ProgressBar" isn't a bar by default. It is more of a
     * circle. We didn't make the rules (or the names of Views), we just follow them.
     */
    mLoadingIndicator = (ProgressBar) findViewById(R.id.pb_loading_indicator);

    /*
     * This ID will uniquely identify the Loader. We can use it, for example, to get a handle
     * on our Loader at a later point in time through the support LoaderManager.
     */
    int loaderId = FORECAST_LOADER_ID;

    /*
     * From MainActivity, we have implemented the LoaderCallbacks interface with the type of
     * String array. (implements LoaderCallbacks<String[]>) The variable callback is passed
     * to the call to initLoader below. This means that whenever the loaderManager has
     * something to notify us of, it will do so through this callback.
     */
    LoaderCallbacks<String[]> callback = MainActivity.this;

    /*
     * The second parameter of the initLoader method below is a Bundle. Optionally, you can
     * pass a Bundle to initLoader that you can then access from within the onCreateLoader
     * callback. In our case, we don't actually use the Bundle, but it's here in case we wanted
     * to.
     */
    Bundle bundleForLoader = null;

    /*
     * Ensures a loader is initialized and active. If the loader doesn't already exist, one is
     * created and (if the activity/fragment is currently started) starts the loader. Otherwise
     * the last created loader is re-used.
     */
    getSupportLoaderManager().initLoader(loaderId, bundleForLoader, callback);

    Log.d(TAG, "onCreate: registering preference changed listener");

    /*
     * Register MainActivity as an OnPreferenceChangedListener to receive a callback when a
     * SharedPreference has changed. Please note that we must unregister MainActivity as an
     * OnSharedPreferenceChanged listener in onDestroy to avoid any memory leaks.
     */
    PreferenceManager.getDefaultSharedPreferences(this)
            .registerOnSharedPreferenceChangeListener(this);
}
 
Example 20
Source File: MainActivity.java    From ratebeer with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);

	if (Session.get().isUpgrade()) {
		startActivity(UpgradeActivity.start(this));
		finish();
		return;
	} else if (!Session.get().hasIgnoredAccount() && !Session.get().isLoggedIn()) {
		startActivity(WelcomeActivity.start(this));
		finish();
		return;
	}

	View scanButton = findViewById(R.id.scan_button);
	View helpButton = findViewById(R.id.help_button);
	searchEdit = (SearchView) findViewById(R.id.search_edit);
	TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
	listsPager = (ViewPager) findViewById(R.id.lists_pager);
	loadingProgress = findViewById(R.id.loading_progress);
	statusText = (TextView) findViewById(R.id.status_text);
	emptyText = (TextView) findViewById(R.id.empty_text);
	RecyclerView searchList = (RecyclerView) findViewById(R.id.search_list);
	rateButton = (FloatingActionButton) findViewById(R.id.rate_button);
	listAddButton = (FloatingActionButton) findViewById(R.id.list_add_button);

	// Set up tabs
	tabTypes = new ArrayList<>(3);
	tabs = new ArrayList<>(3);
	tabsTitles = new ArrayList<>(3);
	if (Session.get().isLoggedIn()) {
		addTab(TAB_RATINGS, R.string.main_myratings);
		addTab(TAB_FEED_FRIENDS, R.string.main_friends);
		addTab(TAB_FEED_LOCAL, R.string.main_local);
	} else {
		addTab(TAB_FEED_GLOBAL, R.string.main_global);
	}
	addTab(TAB_NEARBY, R.string.main_nearby);
	addTab(TAB_MY_LISTS, R.string.main_mylists);
	addTab(TAB_TOP50, R.string.main_top50);
	RxViewPager.pageSelected(listsPager).subscribe(this::refreshTab);
	listsPager.setAdapter(new ActivityPagerAdapter());
	tabLayout.setupWithViewPager(listsPager);
	if (tabs.size() == 1) {
		tabLayout.setVisibility(View.GONE);
	} else if (tabs.size() > 4) {
		tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
	}

	// Set up access buttons
	RxView.clicks(scanButton)
			.compose(bindToLifecycle())
			.subscribe(v -> new BarcodeIntentIntegrator(this).initiateScan());
	RxView.clicks(helpButton)
			.compose(bindToLifecycle())
			.subscribe(v -> startActivity(HelpActivity.start(this)));
	RxView.clicks(statusText)
			.compose(bindToLifecycle())
			.subscribe(v -> startService(SyncService.start(this)));

	// Set up search box: show results with search view focus, start search on query submit and show suggestions on query text changes
	searchList.setLayoutManager(new LinearLayoutManager(this));
	searchList.setAdapter(searchSuggestionsAdaper = new SearchSuggestionsAdapter());
	ItemClickSupport.addTo(searchList)
			.setOnItemClickListener((parent, pos, v) -> searchFromSuggestion(searchSuggestionsAdaper.get(pos)));
	Observable<SearchViewQueryTextEvent> queryTextChangeEvents = RxSearchView.queryTextChangeEvents(searchEdit)
			.compose(onUi())
			.replay(1)
			.refCount();
	queryTextChangeEvents.map(event -> !TextUtils.isEmpty(event.queryText())).subscribe(hasQuery -> {
		searchList.setVisibility(hasQuery ? View.VISIBLE : View.GONE);
		tabLayout.setVisibility(hasQuery ? View.GONE : (tabs.size() == 1 ? View.GONE : View.VISIBLE));
		scanButton.setVisibility(hasQuery ? View.GONE : View.VISIBLE);
	});
	queryTextChangeEvents
			.filter(SearchViewQueryTextEvent::isSubmitted)
			.subscribe(event -> performSearch(event.queryText().toString()));
	queryTextChangeEvents
			.map(event -> event.queryText().toString())
			.map(String::trim)
			.switchMap(query -> {
				if (query.length() == 0) {
					return Db.getAllHistoricSearches(this).toList();
				} else {
					return Db.getSuggestions(this, query).toList();
				}
			})
			.compose(onIoToUi())
			.compose(bindToLifecycle())
			.subscribe(suggestions -> searchSuggestionsAdaper.update(suggestions));
	searchEdit.setInputType(InputType.TYPE_CLASS_TEXT);

}