I've recycler view with 0 items, I've added an option to manually add the items, my stracture is simple :
MainActivity.java, where the stuff happen.
// My List<Object> List<MyItem> Items = new ArrayList<>(); // For Adding, I've added FAB-Button, When Clicked, it does the following : Items.add(new MyItem()); CheckForEmptyItems(); mAdapter.notifyItemInserted(0); Now, When the user click the save button, i want to take all the edittext in all the items he had added, i'm doing in the following way : for(MyItem items : Items){ Log.i("PrintingInfo", items.getText() ); }
The problem is, i'm not getting the text he entered in all EditText fields, and it's returning Null in all of them, What's the issue in this ?
So, i don't know why always i know the answer after posting, but here's how you gonna know what the user typed :
in your Adapter Class, in onBindViewHolder method, add textlistener for the EditText, here's an example :
holder.MyEditText.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) {
itemList.get(position).setText(s.toString());
}
});
Hope that helps you!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.