1

I have created a custom view as well as corresponding custom attributes. For example

<declare-styleable name="stripbar">
    <attr name="flowDirection" format="string"/>
</declare-styleable>

and

public Stripbar(Context context, AttributeSet attrs)
{
super(context, attrs);

TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.stripbar);
CharSequence flowDirection = ta.getString(R.styleable.stripbar_flowDirection);

String text = attrs.getAttributeValue("android", "text"); 
}

and

<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:ns="http://schemas.android.com/apk/res/com.ns">

            <com.ns.Stripbar
                    android:id="@+id/aaa"
                    ns:flowDirection="RightToLeft"
                    android:text=”yoo hoo”/>

I receive null value for attribute text. I’m also aware of this and do not know how to resolve the issue.

To clarify, I need to obtain my custom attribute value as well as android predefined attribute value side by side?

Any help?

Community
  • 1
  • 1
anonim
  • 2,494
  • 6
  • 30
  • 40

1 Answers1

3

The problem is that your R.styleable.stripbar is actually an array of integers that contains just your flowDirection attribute.

To fix that, you should be able to replace your context.obtainStyledAttributes(attrs, R.styleable.stripbar); with context.obtainStyledAttributes(attrs, new int[]{R.attr.flowDirection, android.R.attr.text});

Then, you should be able to replace ta.getString( R.styleable.stripbar_flowDirection ) with ta.getString(0) and get the text with ta.getString(1).

Jon Shemitz
  • 1,235
  • 13
  • 29