This app contains a recycler cardview ( 2 textviews ) .. how can i share the textview strings using a share button which i have created already..
MyRecycleViewAdapter.java
public class MyRecycleViewAdapter extends RecyclerView.Adapter<MyRecycleViewAdapter.ViewHolder>{
private List<MyQuote> myQuoteList;
private Context mCtx;
public MyRecycleViewAdapter(List<MyQuote> list, Context mCtx) {
this.myQuoteList = list;
this.mCtx = mCtx;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.sample_quotecards, parent, false);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(final MyRecycleViewAdapter.ViewHolder myholder, final int position) {
final MyQuote myQuote = myQuoteList.get(position);
myholder.tv_author.setText(myQuote.getAuthor());
myholder.tv_quote.setText(myQuote.getQuotedesc());
myholder.im_favlike.setImageResource(R.drawable.fav_border);
// share button of a recycler cardview
myholder.buttonViewOption.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//intent to share list values which are already defined to apps like facebook , whatsapp etc
ArrayList<String>testlist = new ArrayList<String>();
testlist.add(myQuoteList.get(position).getAuthor());
testlist.add(myQuoteList.get(position).getQuotedesc());
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, testlist);
shareIntent.setType("image/*");
view.getContext().startActivity(Intent.createChooser(shareIntent , "share this quote via"));
}
});
}
@Override
public int getItemCount() {
return myQuoteList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView tv_author;
public ImageView im_favlike;
public TextView tv_quote;
public ImageButton buttonViewOption;
public ViewHolder(View itemView) {
super(itemView);
im_favlike =(ImageView)itemView.findViewById(R.id.likeimg);
tv_author= (TextView) itemView.findViewById(R.id.author_title);
tv_quote= (TextView) itemView.findViewById(R.id.quote_text);
buttonViewOption = (ImageButton) itemView.findViewById(R.id.imageViewOptions);
}
}
}
MyQuote.java
import android.os.Parcel;
import android.os.Parcelable;
public class MyQuote implements Parcelable{
private String author;
private String quotedesc;
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(quotedesc);
parcel.writeString(author);
}
private MyQuote(Parcel parcel){
quotedesc = parcel.readString();
author = parcel.readString();
}
public static final Parcelable.Creator<MyQuote> CREATOR = new Parcelable.Creator<MyQuote>(){
@Override
public MyQuote createFromParcel(Parcel parcel) {
return new MyQuote(parcel);
}
public MyQuote[] newArray(int size){
return new MyQuote[size];
}
};
//constructor initializing values
public MyQuote(String author, String quotedesc) {
this.quotedesc = quotedesc;
this.author = author;
}
//getters
public String getAuthor() {
return author;
}
public String getQuotedesc() {
return quotedesc;
}
}
im getting the following error when i use intent like this.. Wrong 2nd argument type. Found: 'java.util.ArrayList', required: 'java.util.ArrayList' less... putParcelableArrayListExtra (String, java.util.ArrayList) in Intent cannot be applied to (String, java.util.ArrayList)
public void onBindViewHolder(final MyRecycleViewAdapter.ViewHolder myholder, final int position) {
final MyQuote myQuote = myQuoteList.get(position);
myholder.tv_author.setText(myQuote.getAuthor());
myholder.tv_quote.setText(myQuote.getQuotedesc());
myholder.im_favlike.setImageResource(R.drawable.fav_border);
// share button of a recycler cardview
myholder.buttonViewOption.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//intent to share list values which are already defined to apps like facebook , whatsapp etc
ArrayList<String>testlist = new ArrayList<String>();
testlist.add(myQuoteList.get(position).getAuthor());
testlist.add(myQuoteList.get(position).getQuotedesc());
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, testlist);
shareIntent.setType("image/*");
view.getContext().startActivity(Intent.createChooser(shareIntent , "share quote via"));
}
});
}