Android:XmlPullParser未从Xml文件中提供正确的属性集
这是我的xml文件Android:XmlPullParser未从Xml文件中提供正确的属性集,android,getattribute,android-xmlpullparser,Android,Getattribute,Android Xmlpullparser,这是我的xml文件 <?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
<?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>
在这里,日志显示的是null而不是true
如果你知道我做错了什么,请告诉我。问题出在while循环中,该循环从未执行过,因此我更正了while循环,并正确获取了atributes值。
//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")));