I design one app where I am displaying image using recyclerView. I am not clicking image from camera, its downloded from json api. activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
tools:context="com.bjp.app.bjpapp.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollView">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</ScrollView>
</RelativeLayout>
layout_design.xml this layout file designed for the component views and this file attaching with recyclerView.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="@+id/image"
android:src="@drawable/logo"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@+id/image"
android:layout_weight=".2"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:orientation="horizontal"
android:weightSum="2">
<ImageButton
android:id="@+id/share"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:src="@drawable/share"
android:layout_marginRight="5dp"
android:theme="@style/MyButton1"/>
<ImageButton
android:id="@+id/download"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:src="@drawable/downward"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:theme="@style/MyButton1"/>
</LinearLayout>
</RelativeLayout>
Data.java (Modal class.)
this is my getter and setter class file code.
public class Data implements Serializable {
private int id;
private String imgUrl;
public Data(int id, String imgUrl) {
this.id = id;
this.imgUrl = imgUrl;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getImgUrl() {
return imgUrl;
}
public void setImgUrl(String imgUrl) {
this.imgUrl = imgUrl;
}
}
Adapter class file code is here Image_Adaper.java
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder> {
private List<Data> data;
private Context context;
private Bitmap bitmap;
String url1;
String filepath;
public ImageAdapter(List<Data> data, Context context) {
this.data = data;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_design,parent,false);
return new ImageAdapter.ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
final Data data1=data.get(position);
url1=data1.getImgUrl();
ImageView imageView=holder.imageView;
Glide.with(context)
.load(data1.getImgUrl())
.placeholder(R.drawable.logo)
.into(imageView);
}
@Override
public int getItemCount() {
return data.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
public ImageView imageView;
public ImageButton share,download;
public ViewHolder(final View itemView) {
super(itemView);
imageView=(ImageView)itemView.findViewById(R.id.image);
share=(ImageButton)itemView.findViewById(R.id.share);
download=(ImageButton)itemView.findViewById(R.id.download);
share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int position=getAdapterPosition();
Data data2=data.get(position);
// i want to share a image with social sites
Toast.makeText(context,"Product id "+data2+" btn working",Toast.LENGTH_LONG).show();
}
});
download.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context,"download btn working"+url1,Toast.LENGTH_LONG).show();
}
});
}
}
}
I am attaching the mail layout screenshot for more understanding.
The image should be downloaded on click of the download button. and Image should be shareable to social apps. I tried some code but it is not working. Please, guys, help me to find solutions. Thank you in advance. please find the attachment of this image