0

I am working on an App Which uses lot of qr code scanning. In one of my module I scan code and respective labels related to the scan results are fetched on recyclerView.

Now my layout of this recyclerview list contain a TextView and an editText. My each label in list fetches and comes in with an editText with the help of my adapter class.

Now what i want to do is I want to save data regarding every label through those editext in front of each label. My concern here is how would i do that.

Getting data of each EditText from adapter or my adapter's parent fragment and send it to sevice (here i am using retrofit).

I looked on to web but didn't find any thing much helpful. If anyone can of you can help on this or suggest me some other to do so then it will be great.

Any help will be highly appreciated !!!!

::EDIT::

labelAdapter.java

public class labelsAdapter extends RecyclerView.Adapter<labelsAdapter.UsersViewHolder> {

Context context;
List<LabelModel> userListResponseData;
ArrayList<String> labeldatalist = new ArrayList<String>();

public labelsAdapter(Context context, List<LabelModel> userListResponseData) {
    this.userListResponseData = userListResponseData;
    this.context = context;

}

@Override
public UsersViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    View view = LayoutInflater.from(context).inflate(R.layout.label_list_items, parent,false);
    UsersViewHolder usersViewHolder = new UsersViewHolder(view);
    return usersViewHolder;
}

@Override
public void onBindViewHolder(@NonNull UsersViewHolder usersViewHolder, int i) {

    String label_item = userListResponseData.get(i).getLabel_name();
    usersViewHolder.tv_labelName.setText(label_item);
    usersViewHolder.ed_labelValue.getText().toString();




}



@Override
public int getItemCount() {
    return userListResponseData.size(); // size of the list items
}

class UsersViewHolder extends RecyclerView.ViewHolder {
    // init the item view's
   private TextView tv_labelName;
   private EditText ed_labelValue;

    public UsersViewHolder(View itemView) {
        super(itemView);
        // get the reference of item view's
        tv_labelName = (TextView)itemView.findViewById(R.id.label_list_tv);
        ed_labelValue = (EditText)itemView.findViewById(R.id.label_list_edt);
    }
}
 }
  • I know but my list can vary upto 10-15 (depends on dynamically added labels) then how i suppose to set editText with exact no. as labels @Uday – prashant kumar singh Jan 25 '19 at 06:17
  • You need to be more specific about your problem. What did you try? Can you show us some code? Please [read how to ask a good question](https://stackoverflow.com/help/how-to-ask) then edit your question to improve it. Thank you! – Shanteshwar Inde Jan 25 '19 at 06:17
  • @prashantkumarsingh check this here is the complete solution https://stackoverflow.com/a/51454770/7666442 – AskNilesh Jan 25 '19 at 06:18

2 Answers2

0

Use textchangelistener for adapter edittext and listen for text change in adapter class and then store the value in the backend.

 usersViewHolder.ed_labelValue. addTextChangedListener(new TextWatcher() {

   @Override    
   public void beforeTextChanged(CharSequence s, int start,
     int count, int after) {
   }

   @Override    
   public void onTextChanged(CharSequence s, int start, int before, int count) {

   }

@Override
   public void afterTextChanged(Editable s) {
// add your code here 
}
  });
Ritviz Sharma
  • 310
  • 1
  • 9
0

It is bad practice to put edit text in recycler view. but if you have around 10-15 list than you may be going for that. OR you can open a popup. If you go with the edittext in list than you have to set

yourEt.addTextChangedListener(new TextWatcher() {
    @Override
    public void afterTextChanged(Editable s) {
        // TODO Auto-generated method stub
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        doSomething();
    } 
});
Uday Nayak
  • 429
  • 4
  • 20