How to get custom parameter from custom ui tag

by Ryan » Fri, 18 Sep 2009 12:19:18 GMT


Sponsored Links
 dear all,

I try to implement a custom button(OnPressButton), and the code is in
below.
In LogCat, I can see the two parameters (btn_up/btn_down) value are
below:

btn_...@drawable/btn_up
btn_do...@drawable/btn_up

But how can I convert this to point to R.drowable.btn_up and
R.drowable.btn_down ?

Thank you.

Ryan

#############################################################
In res/layout/main.xml
#############################################################
    <studio.hansung.mobile.tools.ui.OnPressButton
        xmlns:android=" http://schemas.android.com/apk/res/android" ;
        xmlns:app=" http://www.mydomain.test/apk/res/mydomain..tools.ui" ;
        android:id="@+id/btn_opb"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
                app:btn_up="@drawable/btn_up"
                app:btn_down="@drawable/btn_up"
                />

#############################################################
In my Activity class
#############################################################
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        OnPressButton opb = (OnPressButton) findViewById
(R.id.btn_opb);
    }
#############################################################
In my custom button class: OnPressButton.java
#############################################################
        Properties params = null;

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

                // get all params in layout xml
                params =  new Properties();

                for(int i=0; i<attrs.getAttributeCount();i++) {
                        Log.d(tag, "attrs value=" + attrs.getAttributeValue(i));
                        Log.d(tag, "attrs name=" + attrs.getAttributeName(i));
                        
params.put(attrs.getAttributeName(i),attrs.getAttributeValue(i));
                }

                if(params.containsKey("btn_up")) {
                        btn_up = (String)params.get("btn_up");
                        Log.d(tag, "btn_up=" + btn_up);
                }

                if(params.containsKey("btn_down")) {
                        btn_down = (String) params.get("btn_down");
                        Log.d(tag, "btn_down=" + btn_down);
                }
}








--~--~---------~--~----~------------~-------~--~----~



How to get custom parameter from custom ui tag

by Android Box » Sat, 19 Sep 2009 07:05:53 GMT


 Hi,

I have solved this problem, just need to use 
attrs.getAttributeResourceValue() method.
It's like below:

int btn_up = attrs.getAttributeResourceValue("

 http://www.mydomain.test/apk/res/mydomain.tools.ui 

","button_up",-1);

Then I can get the resource id, not a String. Thanks.

Ryan


--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. ImageView not displaying at all

'm not entirely sure what my issue is here.  Basically, I have a set
of PNGs I'm simply trying to display on a page as follows, so see how
they would fit on the page:

Image - Image
  Image
  Image
  Image
  Image

All of the images are in the res/drawable with similar android:src
tags.  What's strange is only the second image (the one on the top
row) is drawing.  All of the rest do not display in the XML preview at
all.  If I use a different image (it's a test image for the icon) for
any of the non-displaying ones, that image does, in fact, display.

I'm guessing there's a problem in the images, but I can't imagine
what.  Any suggestions?  Only thing I can think of is size/dimensions.

--~--~---------~--~----~------------~-------~--~----~

2. Invitation to upload software to Phoload

Hello everyone,

We would like to invite developers to upload their Android software to
a new community mobile software download website called Phoload
(http://www.phoload.com).  Phoload launched last month and is designed
to make discovering and downloading free mobile games and applications
simple, easy and fun.  We are very enthusiastic about the Android
platform, so we will be heavily featuring Android content on the site.

Developers can upload freeware, demo/trial and ad-supported software.
We have a simple and efficient upload process and aim to provide a
great service for developers. Developers uploading their software will
receive pages showcasing their products on the site, regular download
reports, and feedback from the user community.

Please take a look at the Phoload, and if you would like to submit
your software, you can do so by visiting: http://www.phoload.com/developer

Thanks for listening,

Jamie McDonald
--
www.phoload.com

--~--~---------~--~----~------------~-------~--~----~

3. Using the browser environment

4. Android FreeTTS server interfacing, a speech solution for your projects

5. Using an intent to search for a hospital

6. Announcements: Android GUI Prototyping Stencils New Version just released!

7. Announcement: yet another Android GUI prototyping tool