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. File Retriving

Hi fellas,

I am writing a email application so need a help on the following
problem:

How to retrieve a file from path "file:///data/data/<my-app>/files/
sam.txt"

so that i can mail this file using JavaMail API

here file attachment code is:

public void addAttachment(String filename) throws Exception {

            BodyPart messageBodyPart = new MimeBodyPart();
            DataSource source = new FileDataSource(filename);
            messageBodyPart.setDataHandler(new DataHandler(source));
            messageBodyPart.setFileName(filename);

            _multipart.addBodyPart(messageBodyPart);
 }

Note: I don't want the Inbuilt Email app of Android to do the above.


-- 

2. List of command

How do I create a text list, which if clicked create Dialog?

-- 

3. Disable button according to spinner item

4. Sessions in android

5. Could Tabhost bottom border linebe deleted?

6. Trackball clicking a custom preference

7. Need android developers for one of the leading telecommunication company in India