Reading XML-Attributes in the XML-Constuctor of Views

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Reading XML-Attributes in the XML-Constuctor of Views

Postby plusminus » Tue Sep 02, 2008 3:39 am

Reading XML-Attributes in the XML-Constuctor of Views


What you will learn: You will learn how to read out Atributes like [font=Courier New]layout_height[/font] in the XML-Constructor of your custom View.

:?: Problems/Questions: Write it right below...

Difficulty: 1 of 5 :)

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         public MySuperDuperView(Context ctx, AttributeSet attrs, final int cellsEach) {
  2.                 super(ctx, attrs);
  3.                
  4.                 TypedArray a = ctx.obtainStyledAttributes(attrs, android.R.styleable.ViewGroup_Layout);
  5.                
  6.                 this.WIDTH = (int)a.getDimension(android.R.styleable.ViewGroup_Layout_layout_width, MyConstants.NOT_SET);
  7.                 this.HEIGHT = (int)a.getDimension(android.R.styleable.ViewGroup_Layout_layout_height, Constants.NOT_SET);
  8.         }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

Thats it :)


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 7 guests