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?

bacKSlaSh
  • 21
  • 1
  • problem was in while loop which is never gets executed so i corrected my while loop and i got my atrributes value correctly. – bacKSlaSh Oct 05 '15 at 17:35

0 Answers0