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. App2sd partisi sdcard

Pale paragon partition manager. Berhasil brooder
.
Sekedar menginfokan keberhasilan app2sd millestone, many thanks tu letjaw
suhu

-- 
"Indonesian Android Community [id-android]" 

2. Android developers in Houston

I am looking for android developers in houston. Medical center/Katy/Sugar
Land. I have few ideas on which we can work and market the application.

Interested developers please contact.

Thanks

Regards

Ali

--

3. read phone state and "identity"?

4. anyone interested in ThumbEE port of Dalvik?

5. Preferences for input method

6. First time device is turned on

7. NGE CLICK TOMBOL HOME (BERMASALAH)