Android - How To retrieve EditText value from Recy

2019-05-12 02:53发布

How can I retrieve the value from all EditTexts created by the RecyclerView in MainActivity?

In my RecyclerView Adapter I'm extending my inner class:

public class MyPersonalAdapter extends RecyclerView.Adapter<MyPersonalAdapter.MyPersonalViewHolder>

I'm getting a reference to the EditText in that inner class:

 class MyPersonalViewHolder extends RecyclerView.ViewHolder {

        TextView numberTextView;
        EditText nameEditText;

        public MyPersonalViewHolder(View itemView) {
            super(itemView);
            numberTextView = (TextView) itemView.findViewById(R.id.tv_number);
            nameEditText = (EditText) itemView.findViewById(R.id.et_name);
        }
    }

and in my MainActivity I want to use:

for (int i = 0; i < count; i++) {
    String name = "Somehow get that name";
    cv.put(MyContract.MyEntry.COLUMN_NAME, "name");
}

7条回答
再贱就再见
2楼-- · 2019-05-12 03:31

Implement a addTextChangedListener inside bindview method in the recyclerview adapter.

everytime the edittext text is modified in any cell modify the arraylist string at that position.

And later when you need the whole arraylist, just send it back from the adapter class via any public getmethod.

This should be enough.

查看更多
登录 后发表回答