6

I have a strange Error with a ViewGroup. For my main View I use classes in this links ViewFlow project

    java.lang.IllegalArgumentException: parameter must be a descendant of this view
        at android.view.ViewGroup.offsetRectBetweenParentAndChild(ViewGroup.java:4153)
        at android.view.ViewGroup.offsetDescendantRectToMyCoords(ViewGroup.java:4090)
at android.view.ViewRootImpl.scrollToRectOrFocus(ViewRootImpl.java:2129)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:1849)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1641)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2449)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)

This error happens when I try to go back to this view with an Intent or a finish(); method in an other View. When I use the Back Button it's not a problem.

So i don't know why I have this Error. Thanks for your Help.

Substitut
  • 373
  • 1
  • 3
  • 9
  • which party of the code need you ? My initialization of the viewFlow, the code of the Viewflow (already linked) or the code of my second activity where i do the finish(); ? – Substitut May 23 '12 at 14:56

5 Answers5

12

Have the same problem. I use a ViewFlow as the parent view and several GridView as child views.This error happens when I press the Home key and restart the activity again after I scrolled these child views left and right.

Here is my solution:

mViewFlow.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);

Of course, you can config it in layout.xml.

Hope that can help you.

Nodin
  • 136
  • 2
  • 4
  • 2
    please describe solution. – Parixit Mar 25 '14 at 11:14
  • 2
    Hi Parixit, I'm sorry to response to you so late. I have write a blog to analyse this exception, here is the link: http://www.cnblogs.com/monodin/p/3675040.html – Nodin Apr 19 '14 at 16:33
  • 2
    It is written by Chinese, so you may don't understand. But the solutions are at the end of that blog which includes lots of code, and I think you can get some things from them. Also, you are warmly invited to make contact with me. Here is my e-mail: dyj_henu@126.com – Nodin Apr 19 '14 at 16:47
  • 4
    thank you. BUt personal contact is not preferable. Its better that all here get the answer other than personal contact. – Parixit Apr 21 '14 at 07:32
  • TO Parixt:I can't agree with you any more. But I have few idle time to translate them every day. And I will take two weeks off from this weekend. After that,I will translate them as soon as possible. – Nodin Apr 21 '14 at 13:01
  • Is this necessary if I'm using a ```androidx.core.widget.NestedScrollView```? – Sujith S Manjavana Jan 04 '23 at 11:57
4

I had the same issue when deleting item from recycler view which contains EditText. Just before notifying adapter that item was deleted I used

(requireContext() as Activity).currentFocus?.clearFocus()
2

if you are using AdMob banners, add this line, adView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); Some banner ads or the AdView itself may request focus and that may trigger this parameter must be a descendant of this view error.

Sujith S Manjavana
  • 1,417
  • 6
  • 33
  • 60
1

Solved my problem with adding scroll listener.

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    View currentFocus = ((Activity)mContext).getCurrentFocus();
    if (currentFocus != null) {
        currentFocus.clearFocus();
    }  
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Ankur Bavishi
  • 943
  • 12
  • 14
0

This works for me.

convertView = mInflater.inflate(R.layout.row_stat_header,
                    parent, false);  

Here, parent is the ViewGroup parameter in the getView.

Pang
  • 9,564
  • 146
  • 81
  • 122
sarankumar
  • 229
  • 2
  • 7