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 661619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:17:14+00:00 2026-05-13T23:17:14+00:00

In my foo_layout.xml file I have a subclassed RelativeLayout: <?xml version=1.0 encoding=utf-8?> <FrameLayout xmlns:android=http://schemas.android.com/apk/res/android

  • 0

In my foo_layout.xml file I have a subclassed RelativeLayout:


<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <com.android.myapp.FooView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/pegboard_table"
        android:orientation="vertical"
        android:scaleType="fitXY"
        >
        <ImageView   
        android:id="@+id/triangular"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/pegboard_board"
        android:scaleType="fitXY"
    android:gravity="center"
        android:visibility="invisible"
        />
        <Chronometer
        android:id="@+id/timer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/timer_display"
        android:textSize="40sp"
        android:textColor="#000"
        android:layout_alignParentTop="true"
        android:gravity="center"
        android:visibility="invisible"/>
         <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/board_table"
        android:visibility="invisible"
        />
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="center_horizontal"
        android:background="@drawable/tab_bar">
        <!-- android:layout_alignLeft="@id/options_tab"-->
        <ImageView 
        android:id="@+id/game_select"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/game_select" android:paddingLeft="15sp"/>
        <ImageView 
        android:id="@+id/undo_select"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/game_select"
        android:layout_weight="1"
        android:src="@drawable/undo"
        />
        <ImageView 
        android:id="@+id/settings_select"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/undo_select"
        android:layout_weight="1"
        android:src="@drawable/settings"
        />   
        <ImageView 
        android:id="@+id/info_select"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/settings_select"
        android:layout_weight="1"
        android:src="@drawable/info"
        />
    </LinearLayout>
        </com.android.myapp.FooView>
</FrameLayout>

Then I have a java file FooView.java with the class extending
RelativeLayout.


package com.android.myapp;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TableLayout;

public class FooView extends RelativeLayout {

    public FooView(Context context) {
        super(context);
        fillTable();
        // TODO Auto-generated constructor stub
    }

    public FooView(Context context, AttributeSet attrs) {
        super(context, attrs);
        fillTable();
        // TODO Auto-generated constructor stub
    }

    public FooView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        fillTable();
        // TODO Auto-generated constructor stub
    }

    public void fillTable() {
        int board = this.getChildCount();
                View boardView = findViewById(R.id.board_table);
        if (board > 0)
            ;
    }

}

board is always 0.
boardView is always null.

This doesn’t seem like the right behavior. I’ve tried it with other views inside the FooView hierarchy and findViewById() always returns null.

For the life of me I can’t figure out what I’m doing wrong.

  • 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-13T23:17:14+00:00Added an answer on May 13, 2026 at 11:17 pm

    First, your widget is attempting to reference widgets outside of itself. Calling findViewById() will get you children of your widget, not widgets elsewhere in the layout.

    Second, you are trying to do this from your constructor. That is not safe. Please wait until onFinishInflate().

    Third, you may not want to hardwire in R.id values for those other widgets, but allow those to be configurable, either through view attributes or setters. To access those widgets, given the configured IDs, you would call findViewById() not on yourself, but on your activity, obtained from getContext().

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

Sidebar

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.