Kleptine
Kleptine

Reputation: 5085

Access Widget Attribute Through AttributeSet - Android

This should be fairly simple task. I have a view with the following:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:panel="org.miscwidgets"

<org.miscwidgets.widget.Panel
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_gravity="right"
    panel:handle="@+id/panelHandle"
    panel:content="@+id/panelContent"
    panel:position="right">

I am attempting to access the position property in the constructor of the view, however it consistently returns null.

        String posVal = attrs.getAttributeValue("schemas.android.com/apk/gen/org.miscwidgets", "position");

How can I get the value? Is my namespace wrong?

I've seen references to Styleables but I've been unsuccessful in finding any that were not deprecated.

Upvotes: 0

Views: 796

Answers (1)

MByD
MByD

Reputation: 137382

I think you should write in your xml

xmlns:panel="http://schemas.android.com/apk/gen/org.miscwidgets"

Instead of

xmlns:panel="org.miscwidgets"

And get it by

attrs.getAttributeValue("http://schemas.android.com/apk/gen/org.miscwidgets", "position");

Upvotes: 1

Related Questions