Back to project page example.
The source code is released under:
Apache License
If you think the Android project example listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package me.pratama.examplematerial.ui; //w w w. ja va 2s .c o m import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.Menu; import android.view.MenuItem; import java.util.ArrayList; import java.util.List; import butterknife.ButterKnife; import butterknife.InjectView; import me.pratama.examplematerial.BaseActivity; import me.pratama.examplematerial.R; import me.pratama.examplematerial.model.Singer; import me.pratama.examplematerial.ui.adapter.RecyclerAdapter; public class RecyclerViewActivity extends BaseActivity { @InjectView(R.id.recyclerView) RecyclerView recyclerView; private List<Singer> singerList; private RecyclerAdapter recyclerAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_recycler_view); ButterKnife.inject(this); getSupportActionBar().setDisplayHomeAsUpEnabled(true); singerList = new ArrayList<>(); for (int i = 0; i < 10; i++) { singerList.add(new Singer(R.drawable.ic_launcher, "singer " + i)); } recyclerAdapter = new RecyclerAdapter(this, singerList); LinearLayoutManager layoutManager = new LinearLayoutManager(this); recyclerView.setLayoutManager(layoutManager); recyclerView.setAdapter(recyclerAdapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_recycler_view, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }