how to open a activity when a specific item is clicked











up vote
-2
down vote

favorite












You can find the source code here,git,it's not my repo.



I want to open a new activity when a specific book or item is clicked.



I use Recyclerview to display the books in grid.



How handle on clicks, where and how to implement them,thanks in advance.



book.java



public class Book {

private String Title;
private String Category ;
private String Description ;
private int Thumbnail ;

public Book() {
}

public Book(String title, String category, String description, int
thumbnail) {
Title = title;
Category = category;
Description = description;
Thumbnail = thumbnail;
}


public String getTitle() {
return Title;
}

public String getCategory() {
return Category;
}

public String getDescription() {
return Description;
}

public int getThumbnail() {
return Thumbnail;
}


public void setTitle(String title) {
Title = title;
}

public void setCategory(String category) {
Category = category;
}

public void setDescription(String description) {
Description = description;
}

public void setThumbnail(int thumbnail) {
Thumbnail = thumbnail;
}
}


book activity.java



    import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

public class Book_Activity extends AppCompatActivity {

private TextView tvtitle,tvdescription,tvcategory;
private ImageView img;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_book_);

tvtitle = (TextView) findViewById(R.id.txttitle);
tvdescription = (TextView) findViewById(R.id.txtDesc);
tvcategory = (TextView) findViewById(R.id.txtCat);
img = (ImageView) findViewById(R.id.bookthumbnail);

// Recieve data
Intent intent = getIntent();
String Title = intent.getExtras().getString("Title");
String Description = intent.getExtras().getString("Description");
int image = intent.getExtras().getInt("Thumbnail") ;

// Setting values

tvtitle.setText(Title);
tvdescription.setText(Description);
img.setImageResource(image);


}
}


mainactivity.java



  import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

List<Book> lstBook ;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

lstBook = new ArrayList<>();
lstBook.add(new Book("TheVegitarian","Categorie Book","Description
book",R.drawable.thevigitarian));
lstBook.add(new Book("The Wild Robot","Categorie Book","Description
book",R.drawable.thewildrobot));
lstBook.add(new Book("Maria Semples","Categorie Book","Description
book",R.drawable.mariasemples));
lstBook.add(new Book("The Martian","Categorie Book","Description
book",R.drawable.themartian));
lstBook.add(new Book("He Died with...","Categorie Book","Description
book",R.drawable.hediedwith));
lstBook.add(new Book("TheVegitarian","Categorie Book","Description
book",R.drawable.thevigitarian));
lstBook.add(new Book("The Wild Robot","Categorie Book","Description
book",R.drawable.thewildrobot));
lstBook.add(new Book("Maria Semples","Categorie Book","Description
book",R.drawable.mariasemples));
lstBook.add(new Book("The Martian","Categorie Book","Description
book",R.drawable.themartian));
lstBook.add(new Book("He Died with...","Categorie Book","Description
book",R.drawable.hediedwith));
lstBook.add(new Book("TheVegitarian","Categorie Book","Description
book",R.drawable.thevigitarian));
lstBook.add(new Book("The Wild Robot","Categorie Book","Description
book",R.drawable.thewildrobot));
lstBook.add(new Book("Maria Semples","Categorie Book","Description
book",R.drawable.mariasemples));
lstBook.add(new Book("The Martian","Categorie Book","Description
book",R.drawable.themartian));
lstBook.add(new Book("He Died with...","Categorie Book","Description
book",R.drawable.hediedwith));

RecyclerView myrv = (RecyclerView) findViewById(R.id.recyclerview_id);
RecyclerViewAdapter myAdapter = new RecyclerViewAdapter(this,lstBook);
myrv.setLayoutManager(new GridLayoutManager(this,3));
myrv.setAdapter(myAdapter);


}
}


recycle viewadapter.java



 public class RecyclerViewAdapter extends  
RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {

private Context mContext ;
private List<Book> mData ;


public RecyclerViewAdapter(Context mContext, List<Book> mData) {
this.mContext = mContext;
this.mData = mData;
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View view ;
LayoutInflater mInflater = LayoutInflater.from(mContext);
view = mInflater.inflate(R.layout.cardveiw_item_book,parent,false);
return new MyViewHolder(view);
}

@Override
public void onBindViewHolder(MyViewHolder holder, final int position) {

holder.tv_book_title.setText(mData.get(position).getTitle());

holder.img_book_thumbnail.setImageResource(mData.get(position).getThumbnail())
;
holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent intent = new Intent(mContext,Book_Activity.class);

// passing data to the book activity
intent.putExtra("Title",mData.get(position).getTitle());

intent.putExtra("Description",mData.get(position).getDescription());

intent.putExtra("Thumbnail",mData.get(position).getThumbnail());
// start the activity
mContext.startActivity(intent);

}
});



}

@Override
public int getItemCount() {
return mData.size();
}

public static class MyViewHolder extends RecyclerView.ViewHolder {

TextView tv_book_title;
ImageView img_book_thumbnail;
CardView cardView ;

public MyViewHolder(View itemView) {
super(itemView);

tv_book_title = (TextView)
itemView.findViewById(R.id.book_title_id) ;
img_book_thumbnail = (ImageView)
itemView.findViewById(R.id.book_img_id);
cardView = (CardView) itemView.findViewById(R.id.cardview_id);


}
}


}









share|improve this question






















  • What's the error?
    – Skizo-ozᴉʞS
    Nov 10 at 9:10










  • There is no error i want to open an activity when the items in the recyclerview are clicked, not just showing title,descriptions. @Skizo-ozᴉʞS
    – 5NIP3R Xd
    Nov 10 at 9:26










  • and is not opening new activity?
    – Skizo-ozᴉʞS
    Nov 10 at 9:28










  • No,it has only one activity when on clicked,it passes data to the activity related to the book.
    – 5NIP3R Xd
    Nov 10 at 9:38










  • writewhat you want because your code is opening another activity
    – Skizo-ozᴉʞS
    Nov 10 at 9:44















up vote
-2
down vote

favorite












You can find the source code here,git,it's not my repo.



I want to open a new activity when a specific book or item is clicked.



I use Recyclerview to display the books in grid.



How handle on clicks, where and how to implement them,thanks in advance.



book.java



public class Book {

private String Title;
private String Category ;
private String Description ;
private int Thumbnail ;

public Book() {
}

public Book(String title, String category, String description, int
thumbnail) {
Title = title;
Category = category;
Description = description;
Thumbnail = thumbnail;
}


public String getTitle() {
return Title;
}

public String getCategory() {
return Category;
}

public String getDescription() {
return Description;
}

public int getThumbnail() {
return Thumbnail;
}


public void setTitle(String title) {
Title = title;
}

public void setCategory(String category) {
Category = category;
}

public void setDescription(String description) {
Description = description;
}

public void setThumbnail(int thumbnail) {
Thumbnail = thumbnail;
}
}


book activity.java



    import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

public class Book_Activity extends AppCompatActivity {

private TextView tvtitle,tvdescription,tvcategory;
private ImageView img;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_book_);

tvtitle = (TextView) findViewById(R.id.txttitle);
tvdescription = (TextView) findViewById(R.id.txtDesc);
tvcategory = (TextView) findViewById(R.id.txtCat);
img = (ImageView) findViewById(R.id.bookthumbnail);

// Recieve data
Intent intent = getIntent();
String Title = intent.getExtras().getString("Title");
String Description = intent.getExtras().getString("Description");
int image = intent.getExtras().getInt("Thumbnail") ;

// Setting values

tvtitle.setText(Title);
tvdescription.setText(Description);
img.setImageResource(image);


}
}


mainactivity.java



  import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

List<Book> lstBook ;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

lstBook = new ArrayList<>();
lstBook.add(new Book("TheVegitarian","Categorie Book","Description
book",R.drawable.thevigitarian));
lstBook.add(new Book("The Wild Robot","Categorie Book","Description
book",R.drawable.thewildrobot));
lstBook.add(new Book("Maria Semples","Categorie Book","Description
book",R.drawable.mariasemples));
lstBook.add(new Book("The Martian","Categorie Book","Description
book",R.drawable.themartian));
lstBook.add(new Book("He Died with...","Categorie Book","Description
book",R.drawable.hediedwith));
lstBook.add(new Book("TheVegitarian","Categorie Book","Description
book",R.drawable.thevigitarian));
lstBook.add(new Book("The Wild Robot","Categorie Book","Description
book",R.drawable.thewildrobot));
lstBook.add(new Book("Maria Semples","Categorie Book","Description
book",R.drawable.mariasemples));
lstBook.add(new Book("The Martian","Categorie Book","Description
book",R.drawable.themartian));
lstBook.add(new Book("He Died with...","Categorie Book","Description
book",R.drawable.hediedwith));
lstBook.add(new Book("TheVegitarian","Categorie Book","Description
book",R.drawable.thevigitarian));
lstBook.add(new Book("The Wild Robot","Categorie Book","Description
book",R.drawable.thewildrobot));
lstBook.add(new Book("Maria Semples","Categorie Book","Description
book",R.drawable.mariasemples));
lstBook.add(new Book("The Martian","Categorie Book","Description
book",R.drawable.themartian));
lstBook.add(new Book("He Died with...","Categorie Book","Description
book",R.drawable.hediedwith));

RecyclerView myrv = (RecyclerView) findViewById(R.id.recyclerview_id);
RecyclerViewAdapter myAdapter = new RecyclerViewAdapter(this,lstBook);
myrv.setLayoutManager(new GridLayoutManager(this,3));
myrv.setAdapter(myAdapter);


}
}


recycle viewadapter.java



 public class RecyclerViewAdapter extends  
RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {

private Context mContext ;
private List<Book> mData ;


public RecyclerViewAdapter(Context mContext, List<Book> mData) {
this.mContext = mContext;
this.mData = mData;
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View view ;
LayoutInflater mInflater = LayoutInflater.from(mContext);
view = mInflater.inflate(R.layout.cardveiw_item_book,parent,false);
return new MyViewHolder(view);
}

@Override
public void onBindViewHolder(MyViewHolder holder, final int position) {

holder.tv_book_title.setText(mData.get(position).getTitle());

holder.img_book_thumbnail.setImageResource(mData.get(position).getThumbnail())
;
holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent intent = new Intent(mContext,Book_Activity.class);

// passing data to the book activity
intent.putExtra("Title",mData.get(position).getTitle());

intent.putExtra("Description",mData.get(position).getDescription());

intent.putExtra("Thumbnail",mData.get(position).getThumbnail());
// start the activity
mContext.startActivity(intent);

}
});



}

@Override
public int getItemCount() {
return mData.size();
}

public static class MyViewHolder extends RecyclerView.ViewHolder {

TextView tv_book_title;
ImageView img_book_thumbnail;
CardView cardView ;

public MyViewHolder(View itemView) {
super(itemView);

tv_book_title = (TextView)
itemView.findViewById(R.id.book_title_id) ;
img_book_thumbnail = (ImageView)
itemView.findViewById(R.id.book_img_id);
cardView = (CardView) itemView.findViewById(R.id.cardview_id);


}
}


}









share|improve this question






















  • What's the error?
    – Skizo-ozᴉʞS
    Nov 10 at 9:10










  • There is no error i want to open an activity when the items in the recyclerview are clicked, not just showing title,descriptions. @Skizo-ozᴉʞS
    – 5NIP3R Xd
    Nov 10 at 9:26










  • and is not opening new activity?
    – Skizo-ozᴉʞS
    Nov 10 at 9:28










  • No,it has only one activity when on clicked,it passes data to the activity related to the book.
    – 5NIP3R Xd
    Nov 10 at 9:38










  • writewhat you want because your code is opening another activity
    – Skizo-ozᴉʞS
    Nov 10 at 9:44













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











You can find the source code here,git,it's not my repo.



I want to open a new activity when a specific book or item is clicked.



I use Recyclerview to display the books in grid.



How handle on clicks, where and how to implement them,thanks in advance.



book.java



public class Book {

private String Title;
private String Category ;
private String Description ;
private int Thumbnail ;

public Book() {
}

public Book(String title, String category, String description, int
thumbnail) {
Title = title;
Category = category;
Description = description;
Thumbnail = thumbnail;
}


public String getTitle() {
return Title;
}

public String getCategory() {
return Category;
}

public String getDescription() {
return Description;
}

public int getThumbnail() {
return Thumbnail;
}


public void setTitle(String title) {
Title = title;
}

public void setCategory(String category) {
Category = category;
}

public void setDescription(String description) {
Description = description;
}

public void setThumbnail(int thumbnail) {
Thumbnail = thumbnail;
}
}


book activity.java



    import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

public class Book_Activity extends AppCompatActivity {

private TextView tvtitle,tvdescription,tvcategory;
private ImageView img;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_book_);

tvtitle = (TextView) findViewById(R.id.txttitle);
tvdescription = (TextView) findViewById(R.id.txtDesc);
tvcategory = (TextView) findViewById(R.id.txtCat);
img = (ImageView) findViewById(R.id.bookthumbnail);

// Recieve data
Intent intent = getIntent();
String Title = intent.getExtras().getString("Title");
String Description = intent.getExtras().getString("Description");
int image = intent.getExtras().getInt("Thumbnail") ;

// Setting values

tvtitle.setText(Title);
tvdescription.setText(Description);
img.setImageResource(image);


}
}


mainactivity.java



  import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

List<Book> lstBook ;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

lstBook = new ArrayList<>();
lstBook.add(new Book("TheVegitarian","Categorie Book","Description
book",R.drawable.thevigitarian));
lstBook.add(new Book("The Wild Robot","Categorie Book","Description
book",R.drawable.thewildrobot));
lstBook.add(new Book("Maria Semples","Categorie Book","Description
book",R.drawable.mariasemples));
lstBook.add(new Book("The Martian","Categorie Book","Description
book",R.drawable.themartian));
lstBook.add(new Book("He Died with...","Categorie Book","Description
book",R.drawable.hediedwith));
lstBook.add(new Book("TheVegitarian","Categorie Book","Description
book",R.drawable.thevigitarian));
lstBook.add(new Book("The Wild Robot","Categorie Book","Description
book",R.drawable.thewildrobot));
lstBook.add(new Book("Maria Semples","Categorie Book","Description
book",R.drawable.mariasemples));
lstBook.add(new Book("The Martian","Categorie Book","Description
book",R.drawable.themartian));
lstBook.add(new Book("He Died with...","Categorie Book","Description
book",R.drawable.hediedwith));
lstBook.add(new Book("TheVegitarian","Categorie Book","Description
book",R.drawable.thevigitarian));
lstBook.add(new Book("The Wild Robot","Categorie Book","Description
book",R.drawable.thewildrobot));
lstBook.add(new Book("Maria Semples","Categorie Book","Description
book",R.drawable.mariasemples));
lstBook.add(new Book("The Martian","Categorie Book","Description
book",R.drawable.themartian));
lstBook.add(new Book("He Died with...","Categorie Book","Description
book",R.drawable.hediedwith));

RecyclerView myrv = (RecyclerView) findViewById(R.id.recyclerview_id);
RecyclerViewAdapter myAdapter = new RecyclerViewAdapter(this,lstBook);
myrv.setLayoutManager(new GridLayoutManager(this,3));
myrv.setAdapter(myAdapter);


}
}


recycle viewadapter.java



 public class RecyclerViewAdapter extends  
RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {

private Context mContext ;
private List<Book> mData ;


public RecyclerViewAdapter(Context mContext, List<Book> mData) {
this.mContext = mContext;
this.mData = mData;
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View view ;
LayoutInflater mInflater = LayoutInflater.from(mContext);
view = mInflater.inflate(R.layout.cardveiw_item_book,parent,false);
return new MyViewHolder(view);
}

@Override
public void onBindViewHolder(MyViewHolder holder, final int position) {

holder.tv_book_title.setText(mData.get(position).getTitle());

holder.img_book_thumbnail.setImageResource(mData.get(position).getThumbnail())
;
holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent intent = new Intent(mContext,Book_Activity.class);

// passing data to the book activity
intent.putExtra("Title",mData.get(position).getTitle());

intent.putExtra("Description",mData.get(position).getDescription());

intent.putExtra("Thumbnail",mData.get(position).getThumbnail());
// start the activity
mContext.startActivity(intent);

}
});



}

@Override
public int getItemCount() {
return mData.size();
}

public static class MyViewHolder extends RecyclerView.ViewHolder {

TextView tv_book_title;
ImageView img_book_thumbnail;
CardView cardView ;

public MyViewHolder(View itemView) {
super(itemView);

tv_book_title = (TextView)
itemView.findViewById(R.id.book_title_id) ;
img_book_thumbnail = (ImageView)
itemView.findViewById(R.id.book_img_id);
cardView = (CardView) itemView.findViewById(R.id.cardview_id);


}
}


}









share|improve this question













You can find the source code here,git,it's not my repo.



I want to open a new activity when a specific book or item is clicked.



I use Recyclerview to display the books in grid.



How handle on clicks, where and how to implement them,thanks in advance.



book.java



public class Book {

private String Title;
private String Category ;
private String Description ;
private int Thumbnail ;

public Book() {
}

public Book(String title, String category, String description, int
thumbnail) {
Title = title;
Category = category;
Description = description;
Thumbnail = thumbnail;
}


public String getTitle() {
return Title;
}

public String getCategory() {
return Category;
}

public String getDescription() {
return Description;
}

public int getThumbnail() {
return Thumbnail;
}


public void setTitle(String title) {
Title = title;
}

public void setCategory(String category) {
Category = category;
}

public void setDescription(String description) {
Description = description;
}

public void setThumbnail(int thumbnail) {
Thumbnail = thumbnail;
}
}


book activity.java



    import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

public class Book_Activity extends AppCompatActivity {

private TextView tvtitle,tvdescription,tvcategory;
private ImageView img;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_book_);

tvtitle = (TextView) findViewById(R.id.txttitle);
tvdescription = (TextView) findViewById(R.id.txtDesc);
tvcategory = (TextView) findViewById(R.id.txtCat);
img = (ImageView) findViewById(R.id.bookthumbnail);

// Recieve data
Intent intent = getIntent();
String Title = intent.getExtras().getString("Title");
String Description = intent.getExtras().getString("Description");
int image = intent.getExtras().getInt("Thumbnail") ;

// Setting values

tvtitle.setText(Title);
tvdescription.setText(Description);
img.setImageResource(image);


}
}


mainactivity.java



  import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

List<Book> lstBook ;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

lstBook = new ArrayList<>();
lstBook.add(new Book("TheVegitarian","Categorie Book","Description
book",R.drawable.thevigitarian));
lstBook.add(new Book("The Wild Robot","Categorie Book","Description
book",R.drawable.thewildrobot));
lstBook.add(new Book("Maria Semples","Categorie Book","Description
book",R.drawable.mariasemples));
lstBook.add(new Book("The Martian","Categorie Book","Description
book",R.drawable.themartian));
lstBook.add(new Book("He Died with...","Categorie Book","Description
book",R.drawable.hediedwith));
lstBook.add(new Book("TheVegitarian","Categorie Book","Description
book",R.drawable.thevigitarian));
lstBook.add(new Book("The Wild Robot","Categorie Book","Description
book",R.drawable.thewildrobot));
lstBook.add(new Book("Maria Semples","Categorie Book","Description
book",R.drawable.mariasemples));
lstBook.add(new Book("The Martian","Categorie Book","Description
book",R.drawable.themartian));
lstBook.add(new Book("He Died with...","Categorie Book","Description
book",R.drawable.hediedwith));
lstBook.add(new Book("TheVegitarian","Categorie Book","Description
book",R.drawable.thevigitarian));
lstBook.add(new Book("The Wild Robot","Categorie Book","Description
book",R.drawable.thewildrobot));
lstBook.add(new Book("Maria Semples","Categorie Book","Description
book",R.drawable.mariasemples));
lstBook.add(new Book("The Martian","Categorie Book","Description
book",R.drawable.themartian));
lstBook.add(new Book("He Died with...","Categorie Book","Description
book",R.drawable.hediedwith));

RecyclerView myrv = (RecyclerView) findViewById(R.id.recyclerview_id);
RecyclerViewAdapter myAdapter = new RecyclerViewAdapter(this,lstBook);
myrv.setLayoutManager(new GridLayoutManager(this,3));
myrv.setAdapter(myAdapter);


}
}


recycle viewadapter.java



 public class RecyclerViewAdapter extends  
RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {

private Context mContext ;
private List<Book> mData ;


public RecyclerViewAdapter(Context mContext, List<Book> mData) {
this.mContext = mContext;
this.mData = mData;
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View view ;
LayoutInflater mInflater = LayoutInflater.from(mContext);
view = mInflater.inflate(R.layout.cardveiw_item_book,parent,false);
return new MyViewHolder(view);
}

@Override
public void onBindViewHolder(MyViewHolder holder, final int position) {

holder.tv_book_title.setText(mData.get(position).getTitle());

holder.img_book_thumbnail.setImageResource(mData.get(position).getThumbnail())
;
holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent intent = new Intent(mContext,Book_Activity.class);

// passing data to the book activity
intent.putExtra("Title",mData.get(position).getTitle());

intent.putExtra("Description",mData.get(position).getDescription());

intent.putExtra("Thumbnail",mData.get(position).getThumbnail());
// start the activity
mContext.startActivity(intent);

}
});



}

@Override
public int getItemCount() {
return mData.size();
}

public static class MyViewHolder extends RecyclerView.ViewHolder {

TextView tv_book_title;
ImageView img_book_thumbnail;
CardView cardView ;

public MyViewHolder(View itemView) {
super(itemView);

tv_book_title = (TextView)
itemView.findViewById(R.id.book_title_id) ;
img_book_thumbnail = (ImageView)
itemView.findViewById(R.id.book_img_id);
cardView = (CardView) itemView.findViewById(R.id.cardview_id);


}
}


}






java android android-studio






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 9:05









5NIP3R Xd

157




157












  • What's the error?
    – Skizo-ozᴉʞS
    Nov 10 at 9:10










  • There is no error i want to open an activity when the items in the recyclerview are clicked, not just showing title,descriptions. @Skizo-ozᴉʞS
    – 5NIP3R Xd
    Nov 10 at 9:26










  • and is not opening new activity?
    – Skizo-ozᴉʞS
    Nov 10 at 9:28










  • No,it has only one activity when on clicked,it passes data to the activity related to the book.
    – 5NIP3R Xd
    Nov 10 at 9:38










  • writewhat you want because your code is opening another activity
    – Skizo-ozᴉʞS
    Nov 10 at 9:44


















  • What's the error?
    – Skizo-ozᴉʞS
    Nov 10 at 9:10










  • There is no error i want to open an activity when the items in the recyclerview are clicked, not just showing title,descriptions. @Skizo-ozᴉʞS
    – 5NIP3R Xd
    Nov 10 at 9:26










  • and is not opening new activity?
    – Skizo-ozᴉʞS
    Nov 10 at 9:28










  • No,it has only one activity when on clicked,it passes data to the activity related to the book.
    – 5NIP3R Xd
    Nov 10 at 9:38










  • writewhat you want because your code is opening another activity
    – Skizo-ozᴉʞS
    Nov 10 at 9:44
















What's the error?
– Skizo-ozᴉʞS
Nov 10 at 9:10




What's the error?
– Skizo-ozᴉʞS
Nov 10 at 9:10












There is no error i want to open an activity when the items in the recyclerview are clicked, not just showing title,descriptions. @Skizo-ozᴉʞS
– 5NIP3R Xd
Nov 10 at 9:26




There is no error i want to open an activity when the items in the recyclerview are clicked, not just showing title,descriptions. @Skizo-ozᴉʞS
– 5NIP3R Xd
Nov 10 at 9:26












and is not opening new activity?
– Skizo-ozᴉʞS
Nov 10 at 9:28




and is not opening new activity?
– Skizo-ozᴉʞS
Nov 10 at 9:28












No,it has only one activity when on clicked,it passes data to the activity related to the book.
– 5NIP3R Xd
Nov 10 at 9:38




No,it has only one activity when on clicked,it passes data to the activity related to the book.
– 5NIP3R Xd
Nov 10 at 9:38












writewhat you want because your code is opening another activity
– Skizo-ozᴉʞS
Nov 10 at 9:44




writewhat you want because your code is opening another activity
– Skizo-ozᴉʞS
Nov 10 at 9:44

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237482%2fhow-to-open-a-activity-when-a-specific-item-is-clicked%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237482%2fhow-to-open-a-activity-when-a-specific-item-is-clicked%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Landwehr

Reims

Javascript gets undefined on array