को हल करने में विफल रहता है मैं XmlResourceParser के साथ कस्टम एंड्रॉइड टैग को पार्स करने का सही तरीका प्राप्त करना चाहता हूं। मैं एंड्रॉइड प्लग-इन के साथ ग्रहण 3.6 का उपयोग कर रहा हूं, और मुझे name
जैसे कुछ विशेषताओं को strings.xml
से पूर्ण स्ट्रिंग के साथ विस्तारित करना होगा।एंड्रॉइड कस्टम एक्सएमएल पार्सर एंड्रॉइड नेमस्पेस
यहां index.xml
है जिसे res/xml/
फ़ोल्डर में पार्स किया जा रहा है।
<?xml version="1.0" encoding="utf-8"?>
<Index xmlns:android="http://schemas.android.com/apk/res/android">
<Sheet
shortName="o_2sq"
android:name="@string/o_2sq"
instructions=""
/>
</Index>
यहाँ res/values/
फ़ोल्डर
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="o_2sq">Organize two squares</string>
</resources>
में फ़ाइल strings.xml
और कोड टुकड़ा है कि एक XmlResourceParser के साथ पहली index.xml
पार्स करता है:,
String name = xpp.getAttributeValue(null, "android:name");
String shortName = xpp.getAttributeValue(null, "shortName");
चर name
null
होता है, लेकिन shortName
में "o_2sq"
शामिल हैं।
String name = xpp.getAttributeValue("android", "name");
वाक्य लिख ताकि चर नाम "Organize two squares"
होते हैं का सही तरीका क्या है: मैं भी सफलता नहीं मिली निम्नलिखित की कोशिश की?
क्या आपका मतलब 'else {name = s '}' था? ऐसा लगता है कि उस विशेषता को या तो संसाधन या हार्ड-कोड वाली स्ट्रिंग होने की अनुमति होगी, नहीं? –
मुझे अपने मामले में शून्य नहीं होने के लिए नाम की आवश्यकता थी। इसलिए। –