1
In a certain part of my app you will get a Recyclerview as a list of expenses as shown below:
The point is, I want the user to be able to edit expenses at any time just by having a long click, thus replacing them with editable widgets, and at the end of editing, go back to the default presentation view.
package br.com.ivesti.ivesmoney.adapters;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
import br.com.ivesti.ivesmoney.R;
import br.com.ivesti.ivesmoney.database.ExpensesTable;
public class ExpensesAdapter extends RecyclerView.Adapter<ExpensesAdapter.ExpensesHolder> {
private Context mContext;
private List<ExpensesTable> mData = new ArrayList<>();
public ExpensesAdapter(@NonNull Context context, @NonNull List<ExpensesTable> dataSet){
this.mContext = context;
this.mData = dataSet;
}
@NonNull
@Override
public ExpensesHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
return new ExpensesHolder(inflater.inflate(R.layout.expenses_item, parent, false));
}
@Override
public void onBindViewHolder(@NonNull ExpensesHolder holder, int position) {
final ExpensesTable item = mData.get(position);
final int type = item.type;
}
@Override
public int getItemCount() {
return mData.size();
}
protected class ExpensesHolder extends RecyclerView.ViewHolder{
ImageView ivIcon;
Spinner spType;
EditText etValue;
public ExpensesHolder(@NonNull View itemView) {
super(itemView);
ivIcon = (ImageView)itemView.findViewById(R.id.expItemExpIcon);
spType = (Spinner)itemView.findViewById(R.id.expItemSpinner);
etValue = (EditText)itemView.findViewById(R.id.expItemValue);
}
}
}
This is my Adapter, I left the View edition inflated as default, but I wish I could change it on onLongClick(View v)
and then back to the default view