-4

I have a RecyclerView. Each row in the recycler view has an edit text component.

The app crashed when the keyboard is not visible, and user clicks on any of the EditText components in the area that will be occupied by the keyboard once it pops-up. In other words, EditText boxes in the upper half of the screen doesn't throw the exception.

This error is specific to devices with Android 6.0 or more.

For devices with lower version than Android 6.0 , the app works perfectly well as the EditText get automatically scrolled above the keypad.

Following is the exception.

E/AndroidRuntime: FATAL EXCEPTION: main
 Process: in.haplotech.aims, PID: 12723
 java.lang.IllegalArgumentException: parameter must be a descendant of this view
     at android.view.ViewGroup.offsetRectBetweenParentAndChild(ViewGroup.java:5502)
     at android.view.ViewGroup.offsetDescendantRectToMyCoords(ViewGroup.java:5431)
     at android.widget.ScrollView.isWithinDeltaOfScreen(ScrollView.java:1167)
     at android.widget.ScrollView.onSizeChanged(ScrollView.java:1576)
     at android.view.View.sizeChange(View.java:17641)
     at android.view.View.setFrame(View.java:17603)
     at android.view.View.layout(View.java:17520)
     at android.view.ViewGroup.layout(ViewGroup.java:5618)
     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079)
     at android.view.View.layout(View.java:17523)
     at android.view.ViewGroup.layout(ViewGroup.java:5618)
     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
     at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
     at android.view.View.layout(View.java:17523)
     at android.view.ViewGroup.layout(ViewGroup.java:5618)
     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741)
     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
     at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
     at android.view.View.layout(View.java:17523)
     at android.view.ViewGroup.layout(ViewGroup.java:5618)
     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
     at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
     at android.view.View.layout(View.java:17523)
     at android.view.ViewGroup.layout(ViewGroup.java:5618)
     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741)
     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
     at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
     at android.view.View.layout(View.java:17523)
     at android.view.ViewGroup.layout(ViewGroup.java:5618)
     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
     at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
     at com.android.internal.policy.DecorView.onLayout(DecorView.java:724)
     at android.view.View.layout(View.java:17523)
     at android.view.ViewGroup.layout(ViewGroup.java:5618)
     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2374)
     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2101)
     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1278)
     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6357)
     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
     at android.view.Choreographer.doCallbacks(Choreographer.java:683)
     at android.view.Choreographer.doFrame(Choreographer.java:619)
     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
     at android.os.Handler.handleCallback(Handler.java:751)
     at android.os.Handler.dispatchMessage(Handler.java:95)
     at android.os.Looper.loop(Looper.java:154)
     at android.app.ActivityThread.main(ActivityThread.java:6077)
     at java.lang.reflect.Method.invoke(Native Method)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

Following is my Adapter code:

public class StudentAdapter extends RecyclerView.Adapter<StudentAdapter.ViewHolder> {

private Context context;
private List<User> dataList;
private ImageLoader mImageLoader;

public StudentAdapter(List<User> dataList) {
    this.dataList = dataList;
    this.mImageLoader = CustomVolleyRequestQueue.getInstance(AppName.getInstance().getApplicationContext()).getImageLoader();
}

public List<User> getDataList() {
    return dataList;
}


@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    context = parent.getContext();
    LayoutInflater inflater = LayoutInflater.from(context);

    View itemView = inflater.inflate(R.layout.item_exam_student, parent, false);

    ViewHolder viewHolder = new ViewHolder(itemView);
    return viewHolder;
}

@Override
public void onBindViewHolder(ViewHolder viewHolder, int position) {
    final User std = dataList.get(position);

    RelativeLayout studentHolder = viewHolder.studentHolder;
    NetworkImageView imgStudentPic = viewHolder.imgStudentPic;
    final TextView tvName = viewHolder.tvName;
    final EditText etMarks = viewHolder.etMarks;

    tvName.setText(std.toString());
    etMarks.setVisibility(View.GONE);
}

@Override
public int getItemCount() {
    return dataList.size();
}

@Override
public int getItemViewType(int position) {//VVIMP : used to maintain the state of scrolled items.
    //Resource : http://stackoverflow.com/questions/32065267/recyclerview-changing-items-during-scroll
    return position;
}

public static class ViewHolder extends RecyclerView.ViewHolder {

    public RelativeLayout studentHolder;
    public NetworkImageView imgStudentPic;
    public TextView tvName;
    public EditText etMarks;

    public ViewHolder(View itemView) {
        super(itemView);

        studentHolder = (RelativeLayout) itemView.findViewById(R.id.studentHolder);
        imgStudentPic = (NetworkImageView) itemView.findViewById(R.id.imgStudentPic);
        tvName = (TextView) itemView.findViewById(R.id.tvName);
        etMarks = (EditText) itemView.findViewById(R.id.etMarks);
    }
}
}
Sanket
  • 83
  • 1
  • 6
  • add your adapter code as well – Mayank Bhatnagar Oct 09 '17 at 08:33
  • 1
    Possible duplicate of [this question](https://stackoverflow.com/q/7100555/5212133) – Mayank Bhatnagar Oct 09 '17 at 08:36
  • 1
    Possible duplicate of [Preventing/catching "IllegalArgumentException: parameter must be a descendant of this view" error](https://stackoverflow.com/questions/7100555/preventing-catching-illegalargumentexception-parameter-must-be-a-descendant-of) – Selvin Oct 09 '17 at 08:38
  • Can you please describe the problem clearly and with code as well? – Saidur Rahman Oct 09 '17 at 08:40
  • @MayankBhatnagar, The question marked by you, did not solve my problem. – Sanket Oct 09 '17 at 09:15
  • 1
    Please note, I am using a **Recycler View** with an **Edit Text** component in each of the rows. The exception is thrown only after I do some scrolling on the recycler view and then click on any of the edit text boxes. – Sanket Oct 09 '17 at 09:19
  • @Sanket I have tried with edit text in recycler view and it is scrolling perfectly. Even though I tried with "addTextChangedListener" it is not crasing. Do one thing comment complex part of code and try is it crashing because of editText. – suprita Oct 09 '17 at 09:44
  • @suprita, the error is thrown only on devices with **Android 6.0 or more**. Also, the complex logic has been removed, still the problem persists. – Sanket Oct 09 '17 at 11:01
  • I have updated the question with few more insights. It seems the actual problem is with keypad. – Sanket Oct 09 '17 at 12:05

2 Answers2

0

Hello Here is code for adapter I am successfully able to scroll with recycler view containing edit text in each row. public class MovieAdapter extends RecyclerView.Adapter {

private List<Movie> movieList;

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

    View itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.movie_list_row, parent, false);

    return new MovieHolder(itemView);
}

@Override
public void onBindViewHolder(MovieHolder holder, int position) {
    Movie movie = movieList.get(position);

    holder.ed.setText(movie.getTitle());
}
public MovieAdapter(List<Movie> movieList)
{

    this.movieList = movieList;
}


@Override
public int getItemCount() {
    return movieList.size();
}



class MovieHolder extends RecyclerView.ViewHolder
{

    public EditText ed;
    public MovieHolder(View view)
    {
        super(view);

        ed = (EditText) view.findViewById(R.id.name);
    }
}}

MainActivity Class Code:

    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    mAdapter = new MovieAdapter(movieList);

    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(mAdapter);

If you are still getting problem please let me know.

Thanks

suprita
  • 211
  • 1
  • 9
0

I added the following to the activity tag in the android manifest file.

android:windowSoftInputMode="adjustPan"

This is just a temporary solution, as there are few UX issues.

The actual issue can be studied in this question : Recyclerview not scrolling to end when keyboard opens

Sanket
  • 83
  • 1
  • 6