Error In Display Image From Jsonarray To Picasso
I have this JSON link and I parsed it. But when I click on any item I get all the images. What I want is, when user clicks on an item, I want to see the details of only the item
Solution 1:
create an interface class like:
publicinterfaceOnItemClickListener {
voidonItemClick(String item);
}
and implement this class in ImageListFragment.
publicclassImageListFragmentextendsFragmentimplementsOnItemClickListener {
Now when you are creating your adapter object inside ImageListFragment, change your code
imageRecyclerViewadapter = new ImageListAdapter(appShowModules,getContext(),imageUrls);
to
imageRecyclerViewadapter = new ImageListAdapter(appShowModules,getContext(),imageUrls, ImageListFragment.this);
and inside your adapter class, change constructor to
public ImageListAdapter(List<AppShowModule> appShowModules, Context context ,List<String>imageUrls, OnItemClickListener callback){
super();
this.imageUrl =imageUrls;
this.appShowModules = appShowModules;
this.context = context;
this.callback = callback;
}
in your adapter you have to write one more line, which is
private OnItemClickListener callback;
Now inside onBindViewHolder of adapter, write
Baca Juga
- What's The Difference Between Thread.setpriority() And Android.os.process.setthreadpriority()
- How To Handle String Response From Php Using Android Volley Jsonobjectrequest [com.android.volley.parseerror: Org.json.jsonexception]?
- Retrofit2: Convert Json With Dynamic Keys To A Map With Model Also Containing Those Keys
holder.setClickListerner(imageUrl.get(position), callback);
and inside ViewHolder class create setClickListerner method like
publicvoidsetClickListerner(String item, OnItemClickListener callback){
parent.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View v) {
callback.onItemClick(item);
}
});
Now you have ViewHolder like this
classViewHolderextendsRecyclerView.ViewHolder {
public ImageView appImage;
public LinearLayout parent;
publicvoidsetClickListerner(final String item, final OnItemClickListener callback){
parent.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View v) {
callback.onItemClick(item);
}
});
}
publicViewHolder(View itemView) {
super(itemView);
appImage = (ImageView) itemView.findViewById(R.id.appImage);
parent = (LinearLayout) itemView.findViewById(R.id.lnrLayout);
appImage.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View view) {
Intentintent=newIntent(context, ImageShow.class);
intent.putExtra("image", x);
context.startActivity(intent);
}
});
}
}
Now when you click any item onItemClick inside your Fragment class give you select image.
Post a Comment for "Error In Display Image From Jsonarray To Picasso"