2

This is my xml file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<com.example.MyApp.CustomDisplay
   xmlns:custom="http://schemas.android.com/apk/res/com.example.MyApp22"
    android:layout_gravity="center"
    android:layout_alignParentTop="true"
    android:layout_marginTop="10dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    custom:showInput="true"
    custom:showOutput="true"
/>

</RelativeLayout>

I want to use atrribute name "showInput" in my MainActivity. So i found this.

//Code to get atrributes from xml file
Resources res = getResources();
XmlPullParser parser = res.getXml(R.layout.display);
int type = 0;
while (type != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) 
{
    try{
       type = parser.next();
    }catch (Exception e) {
        e.printStackTrace();
    }
    }
    attrs = Xml.asAttributeSet(parser);
  Log.d("Attrbutes",String.valueOf(attrs.getAttributeValue("http://schemas.android.com/apk/res/com.example.sks_calculator","showInput")));

Here Log is showing null instead of true.

Please suggest me if u have any idea what am i doing wrong?

1
  • problem was in while loop which is never gets executed so i corrected my while loop and i got my atrributes value correctly. Commented Oct 5, 2015 at 17:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.