Get the position of clicked item on Recycler View
Date : November 19 2020, 12:35 AM
may help you . Try getAdapterPosition() from inside the view holder so that you may get the adapter position of the click the user made. public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public ViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Toast.makeText(context, String.valueOf(getAdapterPosition()), Toast.LENGTH_SHORT).show();
}
}
|
How to know if view in recycler view item is clicked android
Date : March 29 2020, 07:55 AM
To fix the issue you can do So i have been using recycler view with cardview in android and everything has been working fine...i just need to know how i can be alerted if a view in the list item is clicked not the entire list item it self.Here is my list item xml code , You could set an OnClickListener in the OnBind Method @Override
public void onBindViewHolder(MyViewHolder holder, int position) {
holder.image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//your logic
}
});
}
public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public ImageView image;
public MyViewHolder(View itemView) {
super(itemView);
image = (ImageView) itemView.findViewById(R.id.child_remove);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if(v instanceOf ImageView){
// your logic
}
}
}
|
how to set progress bar when recycler view is clicked
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You have to deal with it in your second activity. There, you should do all your data loading or heavy processing work in a background thread and update the UI as and when you have the data or processing is completed. AsyncTask is designed to serve exactly this purpose public class LoadDataTask extends AsyncTask<Void, Void, Void> {
public LoadDataTask(ProgressDialog progress) {
this.progress = progress;
}
public void onPreExecute() {
progress.show();
}
public void doInBackground(Void... unused) {
... load your image here ...
}
public void onPostExecute(Void unused) {
progress.dismiss();
}
}
ProgressDialog progress = new ProgressDialog(this);
progress.setMessage("Loading...");
new LoadDataTask(progress).execute();
|
display clicked value in recycler view in android
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , HI I'm new to android and I'm fetching data from db and displaying in recycler view. How to get the value of the item clicked. I'm able to get the position but I'm not sure how to get the value. // Click event for all items
@Override
public void onClick(View v) {
DataSearch clickedData = data.get(getPosition());
Toast.makeText(context, "You clicked "+clickedData.getXXX(),Toast.LENGTH_SHORT).show();
}
|
How to get the position of the main recycler view position when inner recycler view item is clicked
Date : March 29 2020, 07:55 AM
it fixes the issue Try below code pass your main recyclerview holder to inner recyclerview like ClassReviewsRecyclerViewAdapter.MyViewHolder myViewHolder;
public ReviewMediaRecyclerViewAdapter(ArrayList<Uploads> data,ClassReviewsRecyclerViewAdapter.MyViewHolder myViewHolder) {
this.dataSet = data;
this.myViewHolder = myViewHolder;
}
((VideoViewHolder)holder).reviewVideo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(),myViewHolder.getAdapterPosition()+"", Toast.LENGTH_SHORT).show();
Intent i= new Intent(((VideoViewHolder)holder).reviewVideo.getContext(), VideoPlayerActivity.class);
i.putExtra("VIDEO_URL",dataSet.get(listPosition).getUploadName());
((VideoViewHolder)holder).reviewVideo.getContext().startActivity(i);
}
});
|