Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6342691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:17:22+00:00 2026-05-24T20:17:22+00:00

Why doesn’t this work? private ScrollView findScrollParent(View v) { if(v==null) { return null; }

  • 0

Why doesn’t this work?

private ScrollView findScrollParent(View v)
{

    if(v==null)
    {
        return null;
    }
    else if(v instanceof ScrollView)
    {
        return (ScrollView) v;
    }
    else
    {
        return findScrollParent((View)v.getParent());
    }
}

CustomView(Context context, AttributeSet as)
{
     super(context,as);
     ScrollView sv = findScrollParent(this);
}

This is my xml file which is inflated:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_height="fill_parent"
     android:layout_width="fill_parent">
<ScrollView
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

  <LinearLayout android:layout_height="wrap_content"
        android:layout_width="wrap_content">

       <com.myapp.CustomView android:layout_height="wrap_content"
               android:layout_width="wrap_content"/>

  </LinearLayout>

</ScrollView>
</RelativeLayout>

I want to have a reference to the scrollView in the custom View. My findScrollParent method finds the LinearLayout then returns null. I call this method in the View v‘s constructor, is that the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:17:23+00:00Added an answer on May 24, 2026 at 8:17 pm

    If you are calling it in the view’s constructor then surely it will not have it’s parent assigned yet?

    As far as I can see from skimming the source the parent attribute is not set until the view is added to the parent at which point it will do something like:

    child.mParent = this;
    

    So if you are in the constructor for the view then my guess is it is too early and the view will be added after it is constructed. I was not 100% sure what combination of classes you were talking about / how you had them fitting together so may have looked at the wrong source.

    EDIT

    Just to clarify with pseudo code the process might look like this

    View view = new View();  // Inside here you are calling your method - which won't work
    addView(view);           // The parent is only just being set as a result of this method
    view.getParent();        // At this point we can now return the expected result
    

    EDIT 2 – @codelark ‘s suggestion

    private _scrollView; // member variable
    
    private ScrollView getScrollView()
    {
       if (null == _scrollView) {
           _scrollView = findScrollParent(this);
       }
       return _scrollView;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why doesn't this work (when parameter is set to 1) : SELECT * FROM
This doesn't work. I've got an exception from SQL databse that column does not
Why doesn't the following work in Python? def make_class(a): class A(object): a=a return A
This doesn't work, it turns it to gibberish: $foo = 'נ'; $bar = mb_convert_encoding($foo,
This doesn't work: if(document.getElementById(iframe).innerHTML==''){ Is there a safe browser reliable way to check an
Why doesn't the CAST work in this MySQL query? SELECT MAX(Signups) AS Max, MIN(Signups)
Why doesn't this jQuery code work? $(document).ready(function () { $('currentPage').click(function() { $('myaccount').slideDown('slow', function() {
This doesn't work: string temp; cout << Press Enter to Continue; cin >> temp;
Why doesn't this work? <script src=Scripts/jquery-1.3.2.js type=text/javascript></script> <script type=text/javascript> $(document).ready(function() { $('.myButton').click(); }); </script>
This doesn't work: >>> pa = Person.objects.all() >>> pa[2].nickname u'arst' >>> pa[2].nickname = 'something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.