Note that there are some explanatory texts on larger screens.

plurals
  1. POView getRootView returns itself
    text
    copied!<p>I have a made a custom Button called ActionButton and I'm trying to get reference to another view that is in a parallel view hierarchy. I thought of using <code>findViewById(int id)</code>, but I kept getting <code>NullPointerExceptions</code>, so I tried to get reference to the RootView via <code>getRootView()</code>, and from there get the view with <code>findViewById(int id)</code>. The problem is now that <code>getRootView</code> instead of returning a layout or null, it returns my ActionButton that called that method.</p> <p>Here is my ActionButton, where I try to get reference:</p> <pre><code>public class ActionButton extends Button { protected void onFinishInflate(){ super.onFinishInflate(); log(getRootView() == this) //true, what I don't understand... ConnectionLayer connectionLayer = (ConnectionLayer) findViewById(R.id.connection_layer); //Returns null... } } </code></pre> <p>And a overview of my layout.xml file:</p> <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" &gt; (much more xml elements) &lt;com.cae.design.reaction.ui.ActionButton android:id="@+id/actionButton" android:layout_width="match_parent" android:layout_height="150dp" android:layout_gravity="center_vertical" /&gt; &lt;/LinearLayout&gt; &lt;com.cae.design.reaction.ui.ConnectionLayer xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/connection_layer" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;/com.cae.design.reaction.ui.ConnectionLayer&gt; &lt;/FrameLayout&gt; </code></pre> <p>I would really appreciate if you could explain to me why <code>getRootView</code> returns the view itself or could give me a hint how I can reference it any other way.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload