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