How to save Edittext value on recycler view to backend

120
January 25, 2019, at 12:20 PM

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);
    }
}
 }
Answer 1

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();
    } 
});
Answer 2

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 
}
  });
READ ALSO
Uncaught mysqli_sql_exception: Unknown column in &#39;where clause&#39;

Uncaught mysqli_sql_exception: Unknown column in 'where clause'

I have a problem with my php code when i try to choose a string in my databaseWell, I have a table "news" and a field "category" (TINYTEXT type) there

137
Use results from a query in another

Use results from a query in another

I'm using Wordpress and the plugin WPForms which stores form entries in my database like so:

113
Related To organization chart

Related To organization chart

I need to develop a java program used to build an organization chartWhat the java program needs to do is to extract the data from the database via JDBC connection and then to build a chart

80