<PreferenceScreen xmlns:androID="http://schemas.androID.com/apk/res/androID" > <Preferencecategory androID:title="About" > <Preference androID:title="Software Version" androID:summary="1.3.554" androID:key="software"/> <Preference androID:title="User" androID:summary="jnovkovic@itekako.com" androID:key="email"/> <Preference androID:title="Terms and conditions" /> </Preferencecategory> <PreferenceScreen androID:key="log_out" androID:layout="@layout/preference_log_out"/></PreferenceScreen>
我这样做了:
PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);Preferencecategory about = new Preferencecategory(this); about.setTitle("About"); root.addPreference(about); Preference software = new Preference(this); software.setTitle("Software Version"); software.setKey("software"); software.setSummary("1.3.554"); about.addPreference(software); Preference user = new Preference(this); user.setTitle("User"); user.setKey("user"); user.setSummary(preferences.getString("user_email","")); about.addPreference(user); Preference terms_and_conditions = new Preference(this); terms_and_conditions.setTitle("Terms and conditions"); terms_and_conditions.setKey("terms_and_conditions"); about.addPreference(terms_and_conditions); relativeLayout layout = new relativeLayout(this); layout.setID(1100); AbsListVIEw.LayoutParams p = new AbsListVIEw.LayoutParams(AbsListVIEw.LayoutParams.MATCH_PARENT,AbsListVIEw.LayoutParams.WRAP_CONTENT); layout.setLayoutParams(p); TextVIEw log_out_text = new TextVIEw(this); relativeLayout.LayoutParams params = new relativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT); log_out_text.setTextSize(TypedValue.COMPLEX_UNIT_SP,18); log_out_text.setTypeface(null,Typeface.BolD); log_out_text.setGravity(Gravity.CENTER); log_out_text.setTextcolor(color.parsecolor("#FFFFFF")); log_out_text.setBackgroundDrawable(log_out_drawable); log_out_text.setLayoutParams(params); layout.addVIEw(log_out_text); Preference log_out = new Preference(this); log_out.setLayoutResource(1100); root.addPreference(log_out); setPreferenceScreen(root);
问题是从上面的第三行……任何人都可以帮助我????
错误是:
01-30 10:56:16.886: E/AndroIDRuntime(3420): FATAL EXCEPTION: main01-30 10:56:16.886: E/AndroIDRuntime(3420): androID.content.res.Resources$NotFoundException: Resource ID #0x44c01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.content.res.Resources.getValue(Resources.java:892)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.content.res.Resources.loadXmlResourceParser(Resources.java:1869)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.content.res.Resources.getLayout(Resources.java:731)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:318)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.preference.Preference.onCreateVIEw(Preference.java:412)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.preference.Preference.getVIEw(Preference.java:389)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.preference.PreferenceGroupAdapter.getVIEw(PreferenceGroupAdapter.java:221)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.Widget.AbsListVIEw.obtainVIEw(AbsListVIEw.java:1554)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.Widget.ListVIEw.makeAndAddVIEw(ListVIEw.java:1793)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.Widget.ListVIEw.fillDown(ListVIEw.java:718)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.Widget.ListVIEw.fillFromtop(ListVIEw.java:775)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.Widget.ListVIEw.layoutChildren(ListVIEw.java:1646)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.Widget.AbsListVIEw.onLayout(AbsListVIEw.java:1384)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.vIEw.VIEw.layout(VIEw.java:7228)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.Widget.FrameLayout.onLayout(FrameLayout.java:338)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.vIEw.VIEw.layout(VIEw.java:7228)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.Widget.linearLayout.setChildFrame(linearLayout.java:1254)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.Widget.linearLayout.layoutVertical(linearLayout.java:1130)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.Widget.linearLayout.onLayout(linearLayout.java:1047)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.vIEw.VIEw.layout(VIEw.java:7228)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.Widget.FrameLayout.onLayout(FrameLayout.java:338)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.vIEw.VIEw.layout(VIEw.java:7228)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.vIEw.VIEwRoot.performTraversals(VIEwRoot.java:1145)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.vIEw.VIEwRoot.handleMessage(VIEwRoot.java:1865)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.os.Handler.dispatchMessage(Handler.java:99)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.os.Looper.loop(Looper.java:130)01-30 10:56:16.886: E/AndroIDRuntime(3420): at androID.app.ActivityThread.main(ActivityThread.java:3687)01-30 10:56:16.886: E/AndroIDRuntime(3420): at java.lang.reflect.Method.invokeNative(Native Method)01-30 10:56:16.886: E/AndroIDRuntime(3420): at java.lang.reflect.Method.invoke(Method.java:507)01-30 10:56:16.886: E/AndroIDRuntime(3420): at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)01-30 10:56:16.886: E/AndroIDRuntime(3420): at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:600)01-30 10:56:16.886: E/AndroIDRuntime(3420): at dalvik.system.NativeStart.main(Native Method)解决方法 你要做的是:创建一个资源programaticaly.你不能这样做.在编译过程中会创建AndroID资源. (基本上xml文件由SDK处理/编译,这就是资源的创建方式).
您可以尝试的是:
>创建自定义公共类MyPreference扩展了Preference
>覆盖onCreateVIEw(VIEwGroup父级)以返回所需的布局.
并使用这样的类:
Preference log_out = new MyPreference(this); root.addPreference(log_out);总结
以上是内存溢出为你收集整理的android – 以编程方式创建布局首选项全部内容,希望文章能够帮你解决android – 以编程方式创建布局首选项所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)