2012-03-12 2 views
3

私はString Fromatを持つLayout.xmlを含むString Inputを持っています。LayoutInflaterを作成する方法入力としてXmlPullParserを指定しますか?

3月12日08:23:12.876:をSystem.err/W(937):android.view.InflateException: START_TAGます。http://

// String that contains the Layout.xml : 

String concat ; 

// Create the XmlPullParser from the String format 

XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); 

factory.setNamespaceAware(true); 

XmlPullParser xpp = factory.newPullParser(); 
xpp.setInput(new StringReader (concat)); 

// create le The LayoutInflater 

LayoutInflater inflater =   (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

View myView = inflater.inflate(xpp, null); 

私はこのバグを持っていますschemas.android.com/apk/res/android}android:orientation='vertical」 {http://schemas.android.com/apk/res/android}アンドロイド:layout_width = 'fill_parent' {http://schemas.android.com/apk/res/android}アンドロイド:layout_height = '1 @ fill_parent'>:Javaで226 。 [email protected]:クラスを拡張するエラー

お願いしますか?

答えて

3

InflaterはXmlBlockのみを受け入れているようです。

私はこれを行うための方法を書かれている、あなたはプロジェクトサイトにリファラができます。 https://github.com/liudongmiao/preference-fragment-compat/blob/master/src/me/piebridge/android/preference/PreferenceFragment.java#L202

メインのコードを次のように:

// byte[] data = ... 
// bytes of compiled xml (unzip the apk, get the bytes from res/layout*/*.xml) 

// XmlBlock block = new XmlBlock(data); 
Class<?> clazz = Class.forName("android.content.res.XmlBlock"); 
Constructor<?> constructor = clazz.getDeclaredConstructor(byte[].class); 
constructor.setAccessible(true); 
Object block = constructor.newInstance(data); 

// XmlPullParser parser = block.newParser(); 
Method method = clazz.getDeclaredMethod("newParser"); 
method.setAccessible(true); 
XmlPullParser parser = method.invoke(block); 
関連する問題