I have a RecyclerView
that contains a multiline EditText
as a list item, the EditText
expands each time a line is added. The RecyclerView
has a standard vertical LinearLayoutManager
and a standard RecyclerView.Adapter<RecyclerView.ViewHolder>
adapter with 15 of the EditText list items. I'll add the code at the end of the question.
The issue is that after you have added a number of lines to the EditText
, it begins to scroll the list down each time a line is added. Eventually, after you have added enough new lines, the EditText will be scrolled off the top of the screen and loses focus. If you try to scroll back up and select the last line of the EditText
, it will scroll the list back down until the EditText
is off the top of the screen and it loses focus.
This isn't an issue for ListView
, only for RecyclerView
.
Does anyone know how to fix or get around this issue?
The line item:
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine|textCapSentences"
android:gravity="top"
android:hint="Enter text"
android:minLines="2"
android:layout_margin="16dp"/>
The RecyclerViewFragment and Adapter
public class RecyclerViewFragment extends Fragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.recycler_view_fragment, container, false);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
recyclerView.setAdapter(new MyAdapter());
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
return view;
}
private class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
{
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
View view = getActivity().getLayoutInflater().inflate(R.layout.edit_text_list_item, parent, false);
MyViewHolder holder = new MyViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
}
@Override
public int getItemCount()
{
return 15;
}
private class MyViewHolder extends RecyclerView.ViewHolder
{
public MyViewHolder(View itemView)
{
super(itemView);
}
}
}
}
This issue was fixed by the latest version of the RecyclerView: 22.2.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With