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

  • SEARCH
  • Home
  • 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 6730107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:22:07+00:00 2026-05-26T10:22:07+00:00

The Situation: I have some custom components in my layout. I have a common

  • 0

The Situation: I have some custom components in my layout. I have a common layout frame that I load in my Activity base class’s onCreate(), and then load my content layouts in my implementations using an inflater, setting the root to the content column of the main layout.

The Problem: When I grab a reference to the Views, to actually extract the user’s input, Activity.findViewById() returns null. It is perhaps a clue that the CheckBox and Button I have in the layout do NOT return null; I get a valid reference to the widget.

Things I’ve Tried: I know I am properly loading and inflating the layout xml, because everything shows up, and the standard Views in the same layout can be found by ID. I can interact with my Views and put content into them and everything, but I can’t get a reference to them in my code.

I have tried cleaning the project, multiple times. R.id is fresh and up-to-date.

I have checked the Console and Error Log, and there’s no UI/XML errors reported.

I tried getting a handle to the root layout of the content I loaded for this activity, and calling View.findViewById() to get my references, and that returns null, too. If I examine the layout in the debugger, I can drill down and find my Views in mChildren.

Perhaps another clue:

public VideoChooser(Context pCtxt, AttributeSet pAttrs)
{
    super(pCtxt, pAttrs);
    Log.d("VideoChooser", "Expected ID: " + R.id.vchShareVids + " | actual: " + getId());
}

will result in the following output:

DEBUG/VideoChooser(10372): Expected ID: 2131296271 | actual: 268435456

The ID assigned to the View doesn’t match the ID in R.id! Why would that be? I know it’s loading the android:id attribute, or else it would be -1 (View.NO_ID).

The Common Layout Frame:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:foo="http://schemas.android.com/apk/res/com.foo"
    android:id="@+id/common_frame" android:orientation="vertical"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <!-- top banner -->
    <LinearLayout android:id="@+id/frame_header" android:orientation="horizontal"
        android:layout_height="wrap_content" android:layout_width="match_parent"
        android:layout_marginBottom="16dp">

        <ImageView android:src="@drawable/banner"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal" android:layout_weight="1" />

    </LinearLayout>

    <!-- content column -->
    <LinearLayout android:id="@+id/frame_content" android:orientation="vertical"
        android:layout_width="match_parent" android:layout_height="wrap_content"
        android:layout_marginLeft="32dp" android:layout_marginRight="32dp" />

</LinearLayout>

The Content Layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:foo="http://schemas.android.com/apk/res/com.foo"
    android:id="@+id/content_panel" android:orientation="vertical"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <com.foo.view.VideoChooser android:id="@+id/vchShareVids"
        foo:prompt_text="@string/prompt_share_vid" foo:prompt_size="16dp"
        foo:preview_height="80dp"
        android:layout_width="match_parent" android:layout_height="wrap_content"
        android:layout_marginBottom="12dp" android:hapticFeedbackEnabled="true" />
    <com.foo.view.ContactChooser android:id="@+id/cchRecipients"
        foo:prompt_text="@string/prompt_share_email" foo:prompt_size="16dp"
        foo:preview_lines="3" foo:dialog_title="Pretend you are picking contacts"
        android:layout_width="match_parent" android:layout_height="wrap_content"
        android:layout_marginBottom="12dp" android:hapticFeedbackEnabled="true" />
    <com.foo.view.TextChooser android:id="@+id/tchDescription"
        foo:prompt_text="@string/prompt_share_description" foo:prompt_size="16dp"
        foo:preview_lines="1" foo:dialog_title="@string/title_msg_chooser_dlg"
        android:layout_width="match_parent" android:layout_height="wrap_content"
        android:layout_marginBottom="12dp" android:hapticFeedbackEnabled="true" />

    <CheckBox android:id="@+id/chkReshare" android:text="@string/prompt_reshare"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:checked="true" android:hapticFeedbackEnabled="true" />
    <Button android:id="@+id/btnSend" android:text="@string/btn_send"
        android:layout_width="@dimen/btn_width" android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal" android:hapticFeedbackEnabled="true" />

</LinearLayout>

Activity Base Class onCreate():

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.common_frame);
}

Activity Implementation onCreate():

@Override
protected void onCreate(Bundle pState)
{
    super.onCreate(pState);
    load_content_view(R.layout.content_layout);

    ViewGroup tLayout = (ViewGroup)findViewById(R.id.content_panel);

    // These all return null
    mCchVideo = (ContentChooser)tLayout.findViewById(R.id.vchShareVids);
    mCchContact = (ContentChooser)tLayout.findViewById(R.id.cchRecipients);
    mCchDescription = (ContentChooser)tLayout.findViewById(R.id.tchDescription);

    // These return valid references
    mChkReshare = (CheckBox)findViewById(R.id.chkReshare);
    mBtnSend = (Button)findViewById(R.id.btnSend);

    // ...
}

protected void load_content_view(int pResId)
{
    LinearLayout tColumn = (LinearLayout)findViewById(R.id.frame_content);
    getLayoutInflater().inflate(pResId, tColumn);
}
  • 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-26T10:22:07+00:00Added an answer on May 26, 2026 at 10:22 am

    Yeah… I’m an idiot. View was of course setting the correct ID, and then one of my init methods went back and clobbered it.

    facepalm

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the situation: We have some generic graphics code that we use for one
Here is the situation. I have some javascript that looks like this: function onSubmit()
Common situation: I have a client on my server who may update some of
I have written a custom control that renders some graphics. The graphics itself is
I have a Setup Project which uses a System.Configuration.Install.Installer Class forhandling some custom actions.
Situation: I have some persons with certain skills and they can/might belong to more
We have a situation where our application calls some stored procedures on a sql
I have a situation where I'm loading some content using a URLLoader but the
I have a situation where I need to notify some users when something in
We have a situation in our product where for a long time some data

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.