Custom XML attributes for imported custom view

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Custom XML attributes for imported custom view

Postby jmar777 » Fri Sep 12, 2008 9:06 pm

I am playing around with custom views and would like to include them in an external library (jar) for the sake of re-usability. I am trying to create some custom attributes for these views that can be set declaratively in the xml.

I have taken a look at the closely related tutorial on PocketBook (http://blog.pocketjourney.com/2008/05/0 ... urce-files - forum won't let me use URL tag on first post?), but from what I can tell it only applies to custom views that exist within an Android project.

Since I am trying to develop these views in an external library, the tutorial hasn't directly related to my situation. Therefore, when I am using one of these imported custom views in an Android project, I can't get the ADT to recognize the custom attributes.

For example, if I put the following in my main.xml:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.         xmlns:m="http://schemas.android.com/apk/res/martin.android.widget"
  3.    android:orientation="vertical"
  4.    android:layout_width="fill_parent"
  5.    android:layout_height="wrap_content"
  6.         >
  7.         <martin.android.widget.NumberPadEditText
  8.                 android:layout_width="fill_parent"
  9.                 android:layout_height="wrap_content"
  10.                 android:text="0.00"
  11.                 android:textColor="#222244"
  12.                 m:keypadBackgroundDrawable="@drawable/popup_bg"
  13.                 />
  14. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


... I get an error stating "No resource identifier found for attribute 'keypadBackgroundDrawable' in package 'martin.android.widget"

To be honest, I am completely clueless as to where android looks to locate the custom attributes. I have tried including an R.java inside of the martin.android.widget package, but either it was formatted incorrectly, or this is the wrong place. Here are the contents of the R.java file:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package martin.android.widget;
  2.  
  3. public final class R {
  4.         /**
  5.          * Custom xml attributes for custom widgets
  6.          */
  7.         public static final class attr {
  8.                 public static final int keypadBackgroundDrawable=0x7f010000;
  9.         }
  10.        
  11.     public static final class styleable {
  12.         public static final int[] NumberPadEditText = {
  13.             0x7f010000
  14.         };
  15.         public static final int NumberPadEditText_keypadBackgroundDrawable = 0;
  16.     };
  17. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


I was assuming that since R.java generally contains resource identifiers, that this is where android would be looking. I have a suspicion I'm on the wrong track altogether though - any pointers would be much appreciated!
jmar777
Freshman
Freshman
 
Posts: 2
Joined: Fri Sep 12, 2008 8:36 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 8 guests