Skip to content

Instantly share code, notes, and snippets.

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder>{
private List<Movie> movieList;
RecyclerViewAdapter(List<Movie> movieList){
this.movieList = movieList;
}
@Override
public RecyclerViewAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public class Movie {
private String title;
private int image;
public Movie(String title, int image) {
this.title = title;
this.image = image;
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:cardView="http://schemas.android.com/apk/res-auto"
android:id="@+id/carView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp">
<FrameLayout
android:layout_width="match_parent"
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private RecyclerTouchListener recycleCTouchListener;
private RecyclerviewItemAdapter recyclerviewItemAdapter;
private List<Items> itemsList;
@Override
protected void onCreate(Bundle savedInstanceState) {
public class RecyclerTouchListener implements RecyclerView.OnItemTouchListener {
private GestureDetector gestureDetector;
private ClickListener clickListener;
public RecyclerTouchListener(Context context, final RecyclerView recyclerView, final ClickListener clickListener) {
this.clickListener = clickListener;
gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
public class RecyclerviewItemAdapter extends RecyclerView.Adapter<RecyclerviewItemAdapter.MyViewHolder> {
private List<Items> itemsList;
class MyViewHolder extends RecyclerView.ViewHolder{
public TextView name,price;
public MyViewHolder(View itemView) {
super(itemView);
public interface ClickListener {
void onClick(View view, int position);
void onLongClick(View view, int position);
}
public class Items {
private String name;
private int price;
Items(String mName,int mPrice){
this.name = mName;
this.price = mPrice;
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycleView"
android:layout_width="match_parent"