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. Using the GeoCoder in Realtime Navigation Application

Hello advocates,

I was wondering, whether we are allowed to use the GeoCoder-Class in
order to search for Locations that are used in a realtime navigation
application? (NOT using any map-imagery or driving-directions, JUST
using the GeoCoder).

Regards,
plusminus
--~--~---------~--~----~------------~-------~--~----~

2. Access to the SMS inbox

I'm interested in writing an App that would export the SMS inbox to SD
card or other external storage.  Is there any class that provides
access to this inbox?  I don't see it in the content provider
documentation.

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

3. Activity.setResult(RESULT_OK, intent) resulting in RESULT_CANCELED

4. Progress Bar before an Activity

5. Custom background for selected Listview Items

6. Problem doing the programming tutorial

7. Handling Symbol Keys using onKeyDown