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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:25:55+00:00 2026-06-09T17:25:55+00:00

I have a custom view, extending LinearLayout and im trying to add some custom

  • 0

I have a custom view, extending LinearLayout and im trying to add some custom attributes, like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- other stuff -->
    <declare-styleable name="UIPlayer">
        <attr name="team" format="integer" />
        <attr name="playAnimation" format="reference" />
    </declare-styleable>
</resources>

My custom view is like this:

public class UIPlayer extends LinearLayout
{    
    // . . .

    public UIPlayer(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
        initAttrs(context, attrs);
    }

    public UIPlayer(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        initAttrs(context, attrs);
    }

    public void initAttrs(Context context, AttributeSet attrs)
    {
        TypedArray taPlayer = context.obtainStyledAttributes(attrs, R.styleable.UIPlayer);
        int team = taPlayer.getInt(R.styleable.UIPlayer_team, -1); 
        player.setTeam(team);

        int animPlayId = taPlayer.getResourceId(R.styleable.UIPlayer_playAnimation, -1);
        try
        {    
            animPlay = AnimationUtils.loadAnimation(context, animPlayId);
        }
        catch (NotFoundException e)
        {
            d("anim", "onPlay not found! " + animPlayId);
        }
        taPlayer.recycle();
    }
    // . . .
}

My layout file is like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:devn="http://schemas.android.com/apk/res/devN.games.mygame"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clipChildren="false"
    android:orientation="vertical"
    android:weightSum="3.0" >

    <devN.games.UIPlayer
        android:id="@+id/player"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:clipChildren="false"
        android:gravity="top"
        devn:playAnimation="@anim/play"
        devn:team="2" >
    </devN.games.UIPlayer>

    <!-- ... -->

</LinearLayout>

What im doing wrong and i cant retrive the animation from within the contstructor? (the “strange fact” is that the team attribute is working fine)

  • 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-06-09T17:25:56+00:00Added an answer on June 9, 2026 at 5:25 pm

    After a lot of studies in android source code, i tried the overload methode:

    obtainStyledAttributes(AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes)
    

    and it worked like a charm!! 🙂
    So the correct code is:

    TypedArray taPlayer = context.obtainStyledAttributes(attrs, R.styleable.UIPlayer, 0, 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom view that looks a little like a speedometer. <?xml version=1.0
I have a custom View extending SurfaceView. The XML layout is <com.myPackage.MyCustomView android:id=@+id/mycview android:layout_width=fill_parent
I have created a custom view by extending Relative Layout and it looks like
i have created a My custom listActivty by extending ListActivity like this. public class
I have the following problem: I want to add a custom view (custom_view.xml and
I have a custom View that I would like to embed in an WebView.
I would like to have a custom view in my application that consists of
I want to create a list view custom like this link : http://sites.google.com/site/androideyecontact/_/rsrc/1238086823282/Home/android-eye-contact-lite/eye_contact-list_view_3.png?height=420&width=279 so
I have a custom view extending from View with lots of text drawn at
I have a grid view which is populated using a custom ImageAdapter class extending

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.