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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:14:37+00:00 2026-05-20T11:14:37+00:00

I have an Activity that inflates an XML FrameLayout that has a custom View,

  • 0

I have an Activity that inflates an XML FrameLayout that has a custom View, and a RelativeLayout containing a number of Text/ImageViews:

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

    <my.package.name.CanvasView
        android:id="@+id/canvas"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="true" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="24dp"
        android:background="#66000000">
    <TextView 
        android:id="@+id/toolbar_time"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:gravity="right|center_vertical"
        android:textColor="#FFFFFFFF"
        android:shadowColor="#000000"
        android:shadowDx="1"
        android:shadowDy="1"
        android:shadowRadius="2" />
    <ImageView
        android:id="@+id/toolbar_notification"
        android:layout_toLeftOf="@+id/toolbar_time"
        android:layout_width="20dp"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:gravity="center|center_vertical" />
    <TextView 
        android:id="@+id/toolbar_title"
        android:layout_toLeftOf="@+id/toolbar_notification"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:gravity="left|center_vertical"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:textColor="#FFFFFFFF"
        android:shadowColor="#000000"
        android:shadowDx="1"
        android:shadowDy="1"
        android:shadowRadius="2" />
    </RelativeLayout>
</FrameLayout>

In the custom ‘CanvasView’, I do some drawing, and intercept onTouchEvent(), etc. Based on the user’s actions in the View I’d like to update one of the TextView’s, specifically toolbar_notification. It would be best to do this in the CanvasView itself, but as the TextView is not a childview of it, I can’t access it via findViewById().

I’ve tried this solution, but I get a RuntimeException of “Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class my.package.name.CanvasView” everytime I try to access the parent View’s properties via:

ViewGroup parentView = (ViewGroup) getParent();
parentView.getChildCount();

Any suggestions?

Thanks,

Paul

  • 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-20T11:14:38+00:00Added an answer on May 20, 2026 at 11:14 am

    I would create a Listener interface on your custom Canvas and have your Activity implement it. In your touch event you can call the Listener method and get back into the Activity.

    Reasons to do so:

    • Your activity already knows about all of the views in the hierarchy.
    • This method will still work even if your TextView moves around.
    • More consistent with the way the framework works

    In your custom Canvas:

    public static interface Listener {
        public void someEventHappened(String moreInfo);
    }
    
    private Listener listener;
    
    public void setListener(Listener listener) { this.listener = listener; }
    

    In your Activity, implement the interface

    public class MyActivity extends Activity implements MyCanvas.Listener { ...

    and set the listener in your onCreate() method in your activity:

    myCanvas.setListener(this);

    Then you can put your TextView-changing code in the callback inside your Activity:

    public void someEventHappened(String moreInfo) {
        TextView myTextView = (TextView) findViewById(R.id.my_text_view);
        myTextView.setText(moreInfo);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.