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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:40:44+00:00 2026-05-31T15:40:44+00:00

I’ve been working on a Custom Control for Android and although I tried to

  • 0

I’ve been working on a Custom Control for Android and although I tried to do what’s suggested here there seems to be something I’m doing wrong.

Here’s my code to see if anyone can spot the problem:

MyComponent.java

public MyComponent(Context context, AttributeSet attrs) 
{
  super(context);
  TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.MyComponent); 
  CharSequence myId = arr.getString(R.styleable.MyComponent_identifier); 

  if (myId != null) 
  {   
    this.setIdentifier(myId.toString()); 
  }

  Integer cds = arr.getInteger(R.styleable.MyComponent_cd_number, 0);

  if(cds != null)
  {
    this.setCds(cds);
  }

  arr.recycle();
 }

attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>   
   <declare-styleable name="MyComponent">     
    <attr name="cd_number" format="integer" />   
    <attr name="identifier" format="string" />
   </declare-styleable> 
</resources> 

main.xml

<TableLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:bgl="http://schemas.android.com/apk/res/my.test.package.components"
  android:id="@+id/table"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  ...

  <my.test.package.MyComponent 
     android:id="@+id/hand"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_span="2"
        bgl:cd_number="4"
        bgl:identifier="plr"/>

   ...

  </TableLayout>

When I put this I get the following errors:

error: No resource identifier found for attribute ‘cd_number’ in package ‘my.test.package’
error: No resource identifier found for attribute ‘identifier’ in package ‘my.test.package’

If I change my namespace to something like:

xmlns:bgl="http://schemas.mywhatever.com/apk/res/my.test.package"

…the errors go way and the thing runs but myId is null and cds is 0 (the default value!) back on the MyComponent.java constructor.

I’d say it’s some very basic mistake but I not being able to spot it and since there’s not much documentation on this I decided to ask here.

Thanks in advance!

  • 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-31T15:40:45+00:00Added an answer on May 31, 2026 at 3:40 pm

    Ok. I got it solved!

    On the original post I had:

    xmlns:bgl="http://schemas.android.com/apk/res/my.test.package
    

    …but in my source I had:

    xmlns:bgl="http://schemas.android.com/apk/res/my.test.package.components
    

    …because I thought one should put the URI to the components package.

    THIS IS WRONG!

    On the xmlns it should be the application name as is declared on the Manifest!

    When I removed the “components” part of the xmlns it “matched” the application name in the Manifest and the errors went away and when I ran the thing in debug I could actually see the values I was passing to the parameters in the XML!

    Hope this helps someone else! 🙂

    UPDATE

    Later on I had the need to move the control into a library and faced the problem again. It seems that when you put the component in a library and use it on a client app you must declare the xmlns as below:

     xmlns:myns="http://schemas.android.com/apk/res-auto"
    

    If you do so (and have the library declared as an Android dependency) Eclipse (or is it Android?) will search the dependencies for the appropriate attribute bindings.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.