In my application should be a lot of adapters similar to each other and I would like to know whether it is possible to make the interface or superclass to inherit from there and then, instead of writing 10 adapters, thanks !!
My adapter code
public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.NewsViewHolder> {
private List<News> newsList;
private Context ctx;
public NewsAdapter(List<News> newsList, Context ctx) {
this.newsList = newsList;
this.ctx = ctx;
}
static class NewsViewHolder extends RecyclerView.ViewHolder {
CardView cv;
TextView newsTitle;
TextView newsDescription;
ImageView newsImage;
TextView newsDate;
NewsViewHolder(View itemView) {
super(itemView);
cv = (CardView) itemView.findViewById(R.id.cvNews);
newsTitle = (TextView) itemView.findViewById(R.id.title_news);
newsDescription = (TextView) itemView.findViewById(R.id.description_news);
newsDate = (TextView) itemView.findViewById(R.id.date_news);
newsImage = (ImageView) itemView.findViewById(R.id.image_news);
}
}
#Override
public NewsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.news_item, parent,
false);
return new NewsViewHolder(v);
}
#Override
public void onBindViewHolder(NewsViewHolder holder, int position) {
holder.newsTitle.setText(newsList.get(position).newsTitle);
holder.newsDescription.setText(newsList.get(position).newsDescription);
holder.newsDate.setText(newsList.get(position).newsDate);
Glide.with(ctx).load(Constants.SITE + newsList.get(position).newsImage)
.into(holder.newsImage);
}
#Override
public int getItemCount() {
return newsList.size();
}
#Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
}
All should reflect like this
it is possible to make the interface or superclass to inherit from
there and then, instead of writing 10 adapters
It is possible, but of course there must be something in common. For a start the dataset should be homogeneous. E.g. your items should all implement an interface, a contract between the item and the adapter itself. In your case, it could be
public interface DataItem {
String getTitle();
String getDescription();
String getDate();
String getImageUrl();
}
and instead of a private List<News> newsList;, you will have private List<? extends DataItem> newsList;. As I said, all your items have to implement that interface, and the properties have to be accessed through the getters
Related
I made an Adapter for my recyclerView. This adapter works when I use on any xxxActivity.java but when I try to use is on a Fragment Its hows error. Doesn't let me Pass the onClickHandler() that I created in Adapter.
I am Setting Adapter Like this -
events_recyclerview.setAdapter(new FixedPlaceListAdapter(getContext(), placelist, mClickHandler)); //ClickListener doesn't work :'(
Another try was like --
events_recyclerview.setAdapter(new FixedPlaceListAdapter(getContext(), placelist, getmClickHandler()));
Here, I implemented getClickHandler() in the Fragment--
public FixedPlaceListAdapter.FixedPlaceListAdapterOnclickHandler getmClickHandler() {
return mClickHandler;
} //Still doesn't work :'(
and the Adapter Part--
Constructor like this-
public FixedPlaceListAdapter(Context mContext, List<PlaceBean>
placeBeanList, FixedPlaceListAdapterOnclickHandler mClickHandler) {
this.mContext = mContext;
this.placeBeanList = placeBeanList;
this.mClickHandler = mClickHandler;
}
I tried to do this ... but still doesn't work--
events_recyclerview.setAdapter(new FixedPlaceListAdapter(getContext(), placelist, FixedPlaceListAdapter.FixedPlaceListAdapterOnclickHandler.mClickhandler));
here is my full adapter code-
public class FixedPlaceListAdapter extends RecyclerView.Adapter<FixedPlaceListAdapter.FixedPlaceListAdapterViewHolder> {
private final FixedPlaceListAdapterOnclickHandler mClickHandler;
Context mContext;
List<PlaceBean> placeBeanList;
public FixedPlaceListAdapter(Context mContext, List<PlaceBean> placeBeanList, FixedPlaceListAdapterOnclickHandler mClickHandler) {
this.mContext = mContext;
this.placeBeanList = placeBeanList;
this.mClickHandler = mClickHandler;
}
public void setData(List<PlaceBean> placeBeanList) {
this.placeBeanList = placeBeanList;
notifyDataSetChanged();
}
#Override
public FixedPlaceListAdapterViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(R.layout.top_list_single, parent, false);
return new FixedPlaceListAdapterViewHolder(view);
}
#Override
public void onBindViewHolder(FixedPlaceListAdapterViewHolder holder, int position) {
PlaceBean pb = placeBeanList.get(position);
holder.nameTextView.setText(pb.getName());
holder.addressTextView.setText(pb.getVicinity());
holder.rating.setRating(pb.getRating());
if (pb.getPhotoref() != null) {
String imageUrl = UrlsUtil.getSinglePhotoUrlString(mContext, pb.getPhotoref(), "350", "300");
Picasso.with(mContext)
.load(imageUrl)
.into(holder.thumbnailImage);
}
}
#Override
public int getItemCount() {
return placeBeanList.size();
}
public interface FixedPlaceListAdapterOnclickHandler {
void onClick(String id);
}
public class FixedPlaceListAdapterViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView nameTextView;
TextView addressTextView;
RatingBar rating;
ImageView thumbnailImage;
public FixedPlaceListAdapterViewHolder(View itemView) {
super(itemView);
nameTextView = (TextView) itemView.findViewById(R.id.place_name_now_in_list);
addressTextView = (TextView) itemView.findViewById(R.id.address_in_list);
rating = (RatingBar) itemView.findViewById(R.id.rating_single_place_in_list);
thumbnailImage = (ImageView) itemView.findViewById(R.id.place_image_thumb);
itemView.setOnClickListener(this);
}
#Override
public void onClick(View v) {
String placeID = placeBeanList.get(getAdapterPosition()).getPlaceref();
mClickHandler.onClick(placeID);
}
}
}
Need Help!
public class CategoryNewsListAdapter extends RecyclerView.Adapter<CategoryNewsListAdapter.ViewHolder> {
private List<CategoryNews> actors = new ArrayList<>();
private Context mContext;
private Queue<List<CategoryNews>> pendingUpdates =
new ArrayDeque<>();
**public interface NewsItemClickListener {
void onNewsItemClick(int pos, CategoryNews categoryNews, ImageView shareImageView);
}**
**NewsItemClickListener newsItemClickListener;**
public CategoryNewsListAdapter(List<CategoryNews> personList, Context mContext, NewsItemClickListener newsItemClickListener) {
this.actors.addAll(personList);
this.mContext = mContext;
this.newsItemClickListener = newsItemClickListener;
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
final View view = inflater.inflate(R.layout.particular_cat_news_list_row, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
Log.d("BusinessSubCategoryListAdapter", "Bindviewholder without payload");
final CategoryNews newsCategory = actors.get(position);
holder.news_title.setText(newsCategory.getPostTitle());
holder.news_date.setText(newsCategory.getPostDate());
holder.news_category.setText(newsCategory.getCategoryName());
holder.news_description.setText(newsCategory.getPostContent());
// GlideApp
// .with(mContext).load(newsCategory.getPostImage())
// .placeholder(R.mipmap.ic_launcher) // can also be a drawable
// .error(R.drawable.placeholder_image) // will be displayed if the image cannot be loaded
// .crossFade()
// .into(holder.news_image);
Picasso.with(mContext).load(newsCategory.getPostImage()).placeholder(R.drawable.placeholder_image).error(R.drawable.placeholder_image).into(holder.news_image);
**holder.itemView.setOnClickListener(v -> {
newsItemClickListener.onNewsItemClick(position, newsCategory, holder.news_image);
});**
}
#Override
public void onBindViewHolder(ViewHolder holder, int position, List<Object> payloads) {
if (payloads.isEmpty()) {
// if empty, do full binding;
onBindViewHolder(holder, position);
return;
}
Bundle bundle = (Bundle) payloads.get(0);
String newTitle = bundle.getString("NAME_CHANGE");
if (newTitle != null) {
// add some animation if you want
final CategoryNews actor = actors.get(position);
holder.news_title.setText(actor.getPostTitle());
holder.news_date.setText(actor.getPostDate());
holder.news_category.setText(actor.getCategoryName());
holder.news_description.setText(actor.getPostContent());
}
}
public void addItems(List<CategoryNews> newItems) {
// record this value before making any changes to the existing list
int curSize = getItemCount();
// update the existing list
actors.addAll(newItems);
// curSize should represent the first element that got added
// newItems.size() represents the itemCount
notifyItemRangeInserted(curSize, newItems.size());
}
public void updtateItems(List<CategoryNews> newItems) {
// record this value before making any changes to the existing list
int curSize = getItemCount();
// update the existing list
actors.addAll(newItems);
// curSize should represent the first element that got added
// newItems.size() represents the itemCount
notifyItemRangeInserted(0,newItems.size()- getItemCount()-1);
}
#Override
public int getItemCount() {
return actors.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
private TextView news_title, news_date, news_category, news_description;
private ImageView news_image;
public ViewHolder(View itemView) {
super(itemView);
news_title = (TextView) itemView.findViewById(R.id.news_title);
news_date = (TextView) itemView.findViewById(R.id.news_date);
news_category = (TextView) itemView.findViewById(R.id.news_category);
news_description = (TextView) itemView.findViewById(R.id.news_description);
news_image = (ImageView) itemView.findViewById(R.id.news_image);
}
}
}
And In your activity
implements NewsItemClickListener
create object NewsItemClickListener newsItemClickListner;
inside oncreate newsItemClickListner=this; (you mush have implemented 1)
pass that object to recyclerview.
In adapter it is received by this
public CategoryNewsListAdapter(List personList, Context mContext, NewsItemClickListener newsItemClickListener) {
this.actors.addAll(personList);
this.mContext = mContext;
this.newsItemClickListener = newsItemClickListener;
}
In your activity
CategoryNewsListAdapter categoryNewsListAdapter= new CategoryNewsListAdapter(list,this,newsItemClickListner)
After doing all this your overriden method will be called when you click in item of recycler view where you have set onclick listner
Okay .. The Problem is Fixed now ...
I was passing the wrong value or maybe the method of passing the ClickHandler was wrong.
The Solution of the Problem :
I Created another Class for ClickHandler-
public class PlaceCardClickHandler implements
FixedPlaceListAdapter.FixedPlaceListAdapterOnclickHandler,
PlaceListAdapter.PlaceListAdapterOnclickHandler {
Context mContext;
public PlaceCardClickHandler(Context mContext) {
this.mContext = mContext;
}
#Override
public void onClick(String id) {
Intent intentToStartDetail = new Intent(mContext, PlaceDetailActivity.class);
intentToStartDetail.putExtra("id", id);
mContext.startActivity(intentToStartDetail);
}
}
and the change in the Fragment was like this- (Just passed a object from the ClickHandler class)
events_recyclerview.setAdapter(new FixedPlaceListAdapter(getContext(), placelist, new PlaceCardClickHandler(getContext())));
I have a sqlite database with columns NAME,LNAME,LNUMBER,VIOLATION,ARRESTPLACE,ADDRESS,PNUMBER,ONAME,DTIME and I have a recyclerview displays the values of LNAME,LNUMBER, and VIOLATION. I have successfully implemented a onclick method on the recyclerview to pass data to another activity but unfortunately I only know how to pass values that are displayed by the recyclerview but what I want to do is also pass NAME,ARRESTPLACE,ADDRESS,PNUMBER,ONAME,DTIME values even if the recyclerview is not displaying them. What should I do to achieve that? This is what my recyclerview looks like.
CLICK HERE
Here are my recycleradapter codes.
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.MyViewHolder>{
private ArrayList<Violator> arrayList = new ArrayList<>();
Context ctx;
public RecyclerAdapter( ArrayList<Violator> arrayList, Context ctx)
{
this.arrayList = arrayList;
this.ctx = ctx;
}
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_view,parent,false);
MyViewHolder myViewHolder = new MyViewHolder(view,ctx,arrayList);
return myViewHolder;
}
#Override
public void onBindViewHolder(MyViewHolder holder, int position) {
holder.LName.setText("Last Name: "+arrayList.get(position).getLName());
holder.LNumber.setText("License Number: "+arrayList.get(position).getLNumber());
holder.Violation.setText("Violation: "+arrayList.get(position).getViolation());
int sync_status = arrayList.get(position).getSync_status();
if (sync_status == DBContract.SYNC_STATUS_OK)
{
holder.Sync_Status.setImageResource(R.drawable.ok);
holder.Syncstatus.setText("Synced!");
}
else
{
holder.Sync_Status.setImageResource(R.drawable.sync);
holder.Syncstatus.setText("Not Synced!");
}
}
#Override
public int getItemCount()
{
return arrayList.size();
}
public static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener
{
ImageView Sync_Status;
TextView LName;
TextView LNumber;
TextView Violation;
TextView Syncstatus;
ArrayList<Violator> arrayList = new ArrayList<Violator>();
Context ctx;
public MyViewHolder(View itemView, Context ctx, ArrayList<Violator> arrayList)
{
super(itemView);
this.arrayList = arrayList;
this.ctx = ctx;
itemView.setOnClickListener(this);
Sync_Status = (ImageView)itemView.findViewById(R.id.imgSync);
LName = (TextView)itemView.findViewById(R.id.txtLname);
LNumber = (TextView) itemView.findViewById(R.id.txtLnumber);
Violation = (TextView) itemView.findViewById(R.id.txtViolation);
Syncstatus = (TextView) itemView.findViewById(R.id.tvSyncStat);
}
#Override
public void onClick(View v) {
int position = getAdapterPosition();
Violator violator = this.arrayList.get(position);
Intent intent = new Intent(this.ctx, Bluetooth_Activity.class);
intent.putExtra("lastname",violator.getLName());
this.ctx.startActivity(intent);
}
}
}
There are several ways to achieve the result:
1.
Intent intent = new Intent(this.ctx, Bluetooth_Activity.class);
//use the putExtra to add more values
intent.putExtra("lastname",violator.getLName());
intent.putExtra("violation",violator.getViolation());
//...and so on
this.ctx.startActivity(intent);
Make your violator class implement Parcelable or Serializable and use the putExtra method like below:
//here I'm using a serializable implementation
intent.putExtra("my_violator_item", (Serializable) violator);
Pass Violator object to intent after implementing Serializable or Parsable Interface to Violator class.
For example:
Intent intent = new Intent(this.ctx, Bluetooth_Activity.class);
intent.putExtra("myViolator",violator);
this.ctx.startActivity(intent);
Make your Violator class Parcelable and send the complete array list as intent.putParcelableArrayListExtra() and get it on another end.
I have a RecyclerView with a custom listener that I want to implement in my main activity so that it gets notified when the RecyclerView item gets clicked.
However, I'm not sure where to put setMyAdapterListener in the adapter. Where would I put it?
public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context context;
private List<Data> data;
private MyAdapterListener myAdapterListener;
public MyAdapter(Context context, List<Object> data) {
this.context = context;
this.data = data;
}
public interface MyAdapterListener {
void onContainerClick();
}
public void setMyAdapterListener(MyAdapterListener myAdapterListener) {
this.myAdapterListener = myAdapterListener;
}
public class ViewHolderItem extends RecyclerView.ViewHolder implements View.OnClickListener {
public LinearLayout container;
public ImageView poster;
public ViewHolderItem(View v) {
super(v);
container = (LinearLayout) v.findViewById(R.id.container);
poster = (ImageView) v.findViewById(R.id.poster);
}
#Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.container) {
if (myAdapterListener != null) {
myAdapterListener.onContainerClick();
}
}
}
}
#Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
RecyclerView.ViewHolder viewHolder = null;
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View v2 = inflater.inflate(R.layout.item_layout, parent, false);
viewHolder = new ViewHolderItem(v2);
return viewHolder;
}
#Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
Data item = (Data) data.get(position);
holder.poster.setImageDrawable(someDrawable);
}
#Override
public int getItemCount() {
return data.size();
}
}
Remove the setMyAdapter() just pass the arguments you currently have in your setMyAdapterListener as part of your recyclerview's adapter contructor, see below:
public MyAdapter(Context context, List<Object> data, MyAdapterListener myAdapterListener) {
this.context = context;
this.data = data;
this.myAdapterListener = myAdapterListener;
}
//On your activity you have to implement the methods of your interface.
As #ScottS Said you dont need setMyAdapter() method, just pass the onclick listener Interface class as a argument to your adapter constructor then implement the interface methods in activity Class .. code is shown below.
public MyAdapter(Context context, List<Object> data) {
this.context = context;
this.data = data;
this.myAdapterListener = myAdapterListener;
}
public interface MyAdapterListener {
void onContainerClick(); // please provide 2 parameter that will help you more for manipulation like shown below
/// void onContainerClick(View view, int position);
}
}
public class ViewHolderItem extends RecyclerView.ViewHolder implements View.OnClickListener {
public LinearLayout container;
public ImageView poster;
public ViewHolderItem(View v) {
super(v);
container = (LinearLayout) v.findViewById(R.id.container);
poster = (ImageView) v.findViewById(R.id.poster);
container =setOnClickListener(this); /// this line must include
}
#Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.container) {
if (myAdapterListener != null) {
myAdapterListener.onContainerClick();
// myAdapterListener.onContainerClick(v,getAdapterPosition());
}
}
}
}
Then you can handle the events in your Activity or wherever your RecyclerView is being used:
mAdapter = new MyAdapter(getApplicationContext() , data, new MyAdapter.MyAdapterListener() {
#Override
public void onContainerClick(View v, int position) {
Log.d(TAG, "iconTextViewOnClick at position "+position);
}
});
mRecycler.setAdapter(mAdapter);
I have a regular RecyclerView adapter that looks like this:
public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHolder> {
private static final String TAG = "MessageAdapter";
private Context context;
private List<Message> messages;
public MessageAdapter(Context context, List<Message> messages) {
this.context = context;
this.messages = messages;
}
public class ViewHolder extends RecyclerView.ViewHolder {
public Message message;
public TextView messageUser, messageText, messageTime;
public ViewHolder(View v) {
super(v);
messageUser = (TextView) v.findViewById(R.id.messageUser);
messageText = (TextView) v.findViewById(R.id.messageText);
messageTime = (TextView) v.findViewById(R.id.messageTime);
}
public void setMessage(Message message) {
this.message = message;
}
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.message_layout, parent, false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
#Override
public void onBindViewHolder(final ViewHolder holder, int position) {
Message message = messages.get(position);
holder.setMessage(message);
holder.messageUser.setText(message.getUser());
holder.messageText.setText(message.getText());
holder.messageTime.setText(message.getTime());
}
#Override
public int getItemCount() {
return messages.size();
}
}
I use this adapter to list all messages the user has received in the main activity.
In addition to this, I am using the AndroidTreeView library in a different part of my app that also displays the user's messages (but in a treeview layout).
However, reading the documentation of this library, it says that in order to create an adapter for the treeview data, it must have the following format (taken from the docs):
public class MyHolder extends TreeNode.BaseNodeViewHolder<IconTreeItem> {
...
#Override
public View createNodeView(TreeNode node, IconTreeItem value) {
final LayoutInflater inflater = LayoutInflater.from(context);
final View view = inflater.inflate(R.layout.layout_profile_node, null, false);
TextView tvValue = (TextView) view.findViewById(R.id.node_value);
tvValue.setText(value.text);
return view;
}
...
public static class IconTreeItem {
public int icon;
public String text;
}
}
So I created a second message adapter (specifically for the AndroidTreeView library) that looks like this:
public class MessageTreeAdapter extends TreeNode.BaseNodeViewHolder<MessageTreeAdapter.TreeItem> {
private TextView messageUser;
private TextView messageText;
private TextView messageTime;
public MessageTreeAdapter(Context context) {
super(context);
}
#Override
public View createNodeView(TreeNode node, TreeItem value) {
final LayoutInflater inflater = LayoutInflater.from(context);
final View view = inflater.inflate(R.layout.message_layout, null, false);
Message message = value.message;
messageUser = (TextView) v.findViewById(R.id.messageUser);
messageText = (TextView) v.findViewById(R.id.messageText);
messageTime = (TextView) v.findViewById(R.id.messageTime);
messageUser.setText(message.getUser());
messageText.setText(message.getText());
messageTime.setText(message.getTime());
return view;
}
public static class TreeItem {
public Message message;
public TreeItem(Message message) {
this.message = message;
}
}
}
But as you can see, I'm repeating what I already have in my first adapter, MessageAdapter.java. I want to avoid this.
So my question is, how can I use a single adapter (MessageAdapter.java) for both situations so that I don't have to repeat any code.
Create a third class that contains all your shared logic and have your adapters delegate to it.
Personally, I usually create custom view classes when using adapters, which contain all the view related code. Keeps the adapters simple, and makes it easy to reuse the view in different contexts (like in this case different lists/adapters)
I've got a RecyclerView which is loading the content of my String arrays which works fine, however I want to open a new activity depending on which view they have pressed.
What I have done is created an array called classes like so:
<array name="classes">
<item>ClassOne</item>
<item>ClassTwo</item>
<item>ClassThree</item>
<item>ClassFour</item>
</array>
These are stored in an array, and passed to my MainActivityList adapter below:
String[] classes = resource.getStringArray(R.array.classes);
MainActivityList adapter = new MainActivityList(titles,content, images, classes);
recyclerView.setAdapter(adapter);
I've managed to add the OnClickListener to the ViewHolder and output what class is assigned to each view to the log, however I cannot figure out or get working, how to launch another activity.
The class name would be something like ClassOne.class for example
public class MainActivityList extends RecyclerView.Adapter<MainActivityList.ViewHolder> {
private String[] mTitles;
private String[] mContent;
private String[] mClasses;
private TypedArray mImages;
private Context context;
public MainActivityList(String[] titles, String[] content, TypedArray images, String[] classes) {
this.mTitles = titles;
this.mContent = content;
this.mImages = images;
this.mClasses = classes;
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup,int i) {
final View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.activity_main_card, viewGroup, false);
ViewHolder vh = new ViewHolder(v);
v.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ViewHolder vh = (ViewHolder)v.getTag();
Log.v("DEBUG", "Clicked" + vh.classes);
}
});
return vh;
}
public void onBindViewHolder(ViewHolder holder, int position) {
holder.titleView.setText(mTitles[position]);
holder.contentView.setText(mContent[position]);
holder.imageView.setImageDrawable(mImages.getDrawable(position));
holder.classes = mClasses[position];
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView titleView;
public TextView contentView;
public ImageView imageView;
public String classes;
public ViewHolder(View v) {
super(v);
titleView = (TextView) v.findViewById(R.id.card_title);
contentView = (TextView) v.findViewById(R.id.card_content);
imageView = (ImageView)v.findViewById(R.id.card_image);
v.setTag(this);
}
}
#Override
public int getItemCount() {
return mTitles.length;
}
}
Intent intent = new Intent(viewObject.getContext(),ActivityName.class);
viewObject.getContext().startActivity(intent);
I was also looking for a solution, and I found this post:
http://venomvendor.blogspot.sg/2014/07/setting-onitemclicklistener-for-recycler-view.html
By using the OnItemClickListener interface, you should be able to call startActivity in your activity.
adapter.SetOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(View v , int position) {
// This is in an Activity so should be able to start new activity, etc.
}
});
Update: I have tested, the method mentioned in the blog worked for me.