Moving a recyclerviewer to different tab - java

I have 3 fragment(Todo, Ongoing , Finished)
A recyclerviewer populates the first fragment (ToDO). I want to move the recyclerview to the next tab (ongoing). Could not find appropriate documentation on this. Below is a screenshot of the UI
Code for adapter
public class recyclerKanbanAdapter extends RecyclerView.Adapter<recyclerKanbanAdapter.MyViewHolder> {
ArrayList<kanbanItems> kanlist;
Context context;
public recyclerKanbanAdapter(Context context,ArrayList<kanbanItems>kanbanList)
{
this.context=context;
this.kanlist=kanbanList;
}
public recyclerKanbanAdapter.MyViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(context).inflate(R.layout.fragment_itemkanban,parent,false);
return new recyclerKanbanAdapter.MyViewHolder(v);
}
#Override
public void onBindViewHolder(#NonNull recyclerKanbanAdapter.MyViewHolder holder, int position) {
kanbanItems kanban = kanlist.get(position);
holder.contractorName.setText(kanban.getContractorName());
holder.Duration.setText(kanban.getDuration());
holder.taskName.setText(kanban.getTaskName());
holder.btn_Delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
kanlist.remove(holder.getAdapterPosition());
notifyItemRemoved(holder.getAdapterPosition());
notifyItemRangeChanged(holder.getAdapterPosition(), kanlist.size());
}
});
holder.btn_Move.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//move to next tab
}
});
}
#Override
public int getItemCount() {
return kanlist.size();
}
public static class MyViewHolder extends RecyclerView.ViewHolder{
EditText taskName,Duration,contractorName;
ImageButton btn_Delete;
ImageButton btn_Move;
public MyViewHolder(#NonNull View itemView) {
super(itemView);
btn_Move=itemView.findViewById(R.id.btn_move);
btn_Delete=itemView.findViewById(R.id.btn_delete);
taskName= itemView.findViewById(R.id.txtTaskName);
Duration=itemView.findViewById(R.id.txtDuration);
contractorName=itemView.findViewById(R.id.txtContractor);
}
}
}

Related

How to block particular Position in Adapter class ANDROID JAVA

I have an adapter class Where i Want to show a BLOCK USER dialog on particular position.
for example if i want to block position 1 of recyclerView .
So can any one help me porgrammatically?
Given below is the Code Of adapter Please check
I want to block user profile based on Recycler View position
if someone could help me in it please;
public class TableProfileAdapter extends RecyclerView.Adapter<TableProfileAdapter.MyViewHolder> {
Context context;
Activity getActivity;
List<TableProfile> profileUser;
OnRecItemClick onRecItemClick;
private boolean isScaleAnimationDone = false;
private boolean isTimerTextViewActionUpCalled = false;
public TableProfileAdapter(List<TableProfile> profileUser, Context context) {
this.profileUser = profileUser;
this.context = context;
}
#NonNull
#Override
public MyViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.profile_item, parent, false);
return new MyViewHolder(view, onRecItemClick);
}
#Override
public void onBindViewHolder(#NonNull MyViewHolder holder, int position) {
TableProfile data = profileUser.get(position);
holder.tvUserName.setText(data.getProfileName());
Bitmap image = BitmapManager.byteToBitmap(data.getProfileImage());
holder.profilePic.setImageBitmap(image);
if (context instanceof AccessProfileManagementActivity) {
context.startActivity(new Intent(context,HomeActivity.class));
} else if (context instanceof ProfileManagement) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(context, ProfileDetailsActivity.class);
TableProfile model = profileUser.get(holder.getAdapterPosition());
intent.putExtra("DATA", model);
context.startActivity(intent);
notifyDataSetChanged();
((Activity) context).finish();
}
});
}
}
#Override
public int getItemCount() {
return profileUser.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
CircleImageView profilePic;
TextView tvUserName, birthday;
OnRecItemClick onRecItemClick;
RelativeLayout relativeLayout;
public MyViewHolder(#NonNull View itemView, OnRecItemClick onRecItemClick) {
super(itemView);
profilePic = itemView.findViewById(R.id.profileImage);
tvUserName = itemView.findViewById(R.id.userName);
relativeLayout = itemView.findViewById(R.id.relTop);
this.onRecItemClick = onRecItemClick;
itemView.setOnClickListener(this);
}
#Override
public void onClick(View view) {
onRecItemClick.onItemClick(getAdapterPosition());
}
}
public interface OnRecItemClick {
void onItemClick(int position);
}
}

Move a list to the next tab on click a button using tab layout

I have a recycler view on one tab. I am trying to move the recyclerview to the next tab when the user clicks on the next button as shown below. Im having to add the code move on the adapter class. Hence, below is the code for the adapter class. Any idea on how to move the recyclerview to the next tabs (ongoing + finished)
code
public class recyclerKanbanAdapter extends RecyclerView.Adapter<recyclerKanbanAdapter.MyViewHolder> {
ArrayList<kanbanItems> kanlist;
Context context;
public recyclerKanbanAdapter(Context context,ArrayList<kanbanItems>kanbanList)
{
this.context=context;
this.kanlist=kanbanList;
}
public recyclerKanbanAdapter.MyViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(context).inflate(R.layout.fragment_itemkanban,parent,false);
return new recyclerKanbanAdapter.MyViewHolder(v);
}
#Override
public void onBindViewHolder(#NonNull recyclerKanbanAdapter.MyViewHolder holder, int position) {
kanbanItems kanban = kanlist.get(position);
holder.contractorName.setText(kanban.getContractorName());
holder.Duration.setText(kanban.getDuration());
holder.taskName.setText(kanban.getTaskName());
holder.btn_Delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
kanlist.remove(holder.getAdapterPosition());
notifyItemRemoved(holder.getAdapterPosition());
notifyItemRangeChanged(holder.getAdapterPosition(), kanlist.size());
}
});
holder.btn_Move.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//struggling to implemene the move button
}
});
}
#Override
public int getItemCount() {
return kanlist.size();
}
public static class MyViewHolder extends RecyclerView.ViewHolder{
EditText taskName,Duration,contractorName;
ImageButton btn_Delete;
ImageButton btn_Move;
public MyViewHolder(#NonNull View itemView) {
super(itemView);
btn_Move=itemView.findViewById(R.id.btn_move);
btn_Delete=itemView.findViewById(R.id.btn_delete);
taskName= itemView.findViewById(R.id.txtTaskName);
Duration=itemView.findViewById(R.id.txtDuration);
contractorName=itemView.findViewById(R.id.txtContractor);
}
}
}

how to make the progress bar invisible in recyclerview

There is a list of pictures made through RecyclerView. When you click on a picture while it is being transferred to the next activity, a ProgressBar should be displayed. When there is a return to the activity of the image selection, the ProgressBar also remains visible, although it must be hidden.
As I did below, the progress bar becomes invisible only in the first image, but in the rest it does not work. I can’t understand why
in my project there are such classes as:
interface
public interface ImageOnC {
void onClick(int position);
}
ImageViewHolder
public class ImageViewHolder extends RecyclerView.ViewHolder {
public ImageView imageView;
private ImageOnC imageOnC;
public ImageButton imageButton;
public ProgressBar progressBar;
public void setImageOnC(ImageOnC imageOnC) {
this.imageOnC = imageOnC;
}
public ImageViewHolder(#NonNull final View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.image_outline);
progressBar = itemView.findViewById(R.id.progr);
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
imageOnC.onClick(getAdapterPosition());
progressBar.setVisibility(View.VISIBLE);
}
});
}
}
ImageAdabter
public class ImageAdabter extends RecyclerView.Adapter<ImageViewHolder> {
private Context mContext;
private List<Integer> listImages;
public ImageAdabter(Context mContext){
this.mContext = mContext;
this.listImages = getImages();
}
private List<Integer> getImages() {
List<Integer> results = new ArrayList<>();
results.add(R.drawable.outline1);
results.add(R.drawable.outline2);
results.add(R.drawable.outline3);
results.add(R.drawable.outline4);
results.add(R.drawable.outline5);
results.add(R.drawable.outline6);
results.add(R.drawable.outline7);
results.add(R.drawable.outline8);
results.add(R.drawable.outline9);
results.add(R.drawable.outline10);
return results;
}
#NonNull
#Override
public ImageViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mContext).inflate(R.layout.item_images,parent,false);
return new ImageViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull final ImageViewHolder holder, final int position) {
holder.imageView.setImageResource( listImages.get(position));
holder.setImageOnC(new ImageOnC() {
#Override
public void onClick(int position) {
Common.PICTURE_SELECTED = listImages.get(position);
mContext.startActivity(new Intent(mContext, Colorful.class));
}
});
#Override
public void onBindViewHolder(#NonNull ImageViewHolder holder, int position, List<Object>payload){
//if so, then the progress bar only works for the first image in recyclerview
if(!payload.isEmpty()){
if(payload.get(position) instanceof Integer)
holder.progressBar.setVisibility(View.GONE);
}
else super.onBindViewHolder(holder, position, payload);
}
#Override
public int getItemCount() {
return listImages.size();
}
}
I add this to activity
private void initView() {
recyclerView = findViewById(R.id.recycle_view_images);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
adabter = new ImageAdabter(this);
recyclerView.setAdapter(adabter);
}
#Override
public void onResume() {
super.onResume();
if (adabter != null) {
adabter.notifyItemChanged(position, position);
}
}
in xml file use Progress bar visibility gone

How to add a onItemclicklistener method to recycleview of buttons

I want to make a onItemclicklistener method to recycleview of buttons and every button intent to Activity
but the Activity has Textview (every button has different Textview )
public class RecAdapter extends RecyclerView.Adapter<RecAdapter.ViewHolder> {
public class ViewHolder extends RecyclerView.ViewHolder {
Button button;
public ViewHolder(View itemView) {
super(itemView);
button = itemView.findViewById(R.id.buttonn);
}
}
private Context context;
private List<items> items;
public RecAdapter(Context c, List<items> itemList) {
this.context = c;
items = itemList;
}
#Override
public RecAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.buttonss, parent, false);
return new ViewHolder(v);
}
#Override
public void onBindViewHolder(RecAdapter.ViewHolder holder, int position) {
items p = items.get(position);
holder.button.setText(p.getName());
}
#Override
public int getItemCount() {
return items.size();
}
}`
Add OnClickListener on itemView of holder like below:
#Override
public void onBindViewHolder(RecAdapter.ViewHolder holder, int position) {
items p = items.get(position);
holder.button.setText(p.getName());
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Do here
}
});
}

update recycleview row from item onclick

I have a recycleview with 3 texts, is there a way to update specific item onclick that position, (i have quantity of each item, and i want to rise the quantity of that item onclick that position, 0,1,2,3...)
here is my receycleview:
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.RecyclerViewHolder> {
String [] Item_names,Price_items,Item_quantity;
public RecyclerAdapter(String [] Item_names,String [] Price_items,String [] Item_quantity)
{
this.Item_names=Item_names;
this.Price_items=Price_items;
this.Item_quantity=Item_quantity;
}
#Override
public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_layout,parent,false);
RecyclerViewHolder recyclerViewHolder=new RecyclerViewHolder(view);
return recyclerViewHolder;
}
#Override
public void onBindViewHolder(final RecyclerViewHolder holder, final int position) {
holder.ItemNameRecycler.setText(Item_names[position]);
holder.ItemPriceRecycler.setText(Price_items[position]);
holder.ItemQuantityRecycler.setText(Item_quantity[position]);
}
#Override
public int getItemCount() {
return Item_names.length;
}
public static class RecyclerViewHolder extends RecyclerView.ViewHolder{
TextView ItemPriceRecycler,ItemNameRecycler,ItemQuantityRecycler;
public RecyclerViewHolder(View view)
{
super(view);
ItemNameRecycler=(TextView)view.findViewById(R.id.RowItemName);
ItemPriceRecycler=(TextView)view.findViewById(R.id.RowItemPrice);
ItemQuantityRecycler=(TextView)view.findViewById(R.id.RowItemQuantity);
ItemQuantityRecycler.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
}
}
You can use getAdapterPosition
From Documentation:
Returns the Adapter position of the item represented by this
ViewHolder.
in your code:
public static class RecyclerViewHolder extends RecyclerView.ViewHolder{
TextView ItemPriceRecycler,ItemNameRecycler,ItemQuantityRecycler;
public RecyclerViewHolder(View view)
{
super(view);
ItemNameRecycler=(TextView)view.findViewById(R.id.RowItemName);
ItemPriceRecycler=(TextView)view.findViewById(R.id.RowItemPrice);
ItemQuantityRecycler=(TextView)view.findViewById(R.id.RowItemQuantity);
ItemQuantityRecycler.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// get position
int pos = getAdapterPosition(); //get position here
}
});
}
EDIT
for updating the recylerview Item Textview in onClick()
public static class RecyclerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView ItemPriceRecycler, ItemNameRecycler, ItemQuantityRecycler;
public RecyclerViewHolder(final View itemView) {
super(itemView);
ItemNameRecycler = (TextView) itemView.findViewById(R.id.RowItemName);
ItemPriceRecycler = (TextView) itemView.findViewById(R.id.RowItemPrice);
ItemQuantityRecycler = (TextView) itemView.findViewById(R.id.RowItemQuantity);
ItemQuantityRecycler.setOnClickListener(this);
}
// onClick Listener for view
#Override
public void onClick(View v) {
if (v.getId() == ItemQuantityRecycler.getId()) {
int pos = getAdapterPosition();
int value = pos + 1;
Toast.makeText(v.getContext(), "ITEM PRESSED = " + String.valueOf(getAdapterPosition()), Toast.LENGTH_SHORT).show();
ItemQuantityRecycler.setText(String.valueOf(value));
} else {
}
}
}

Categories