2

这是代码:

adapter=new ArrayAdapter<String>(
                this, 
                R.layout.zalistu, 
                android.R.id.text1, 
                values);

所以这是适配器,我在其中为列表 () 进行了自己的设计,R.layout.zalistu并在模拟器中工作,但在设备上它给了我一个错误(应用程序意外停止)如果我使用它,simple_list_item_1那么它在两者上都能正常工作模拟器和我的设备。

这是 R:layout.zalistu:

    <?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:gravity="center_vertical"
    android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
    android:paddingRight="?android:attr/listPreferredItemPaddingRight"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    android:textStyle="bold"
    android:textColor="#FF00FF"
/>

日志猫:

08-13 13:26:15.909: E/AndroidRuntime(6832): FATAL EXCEPTION: main
08-13 13:26:15.909: E/AndroidRuntime(6832): android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.view.LayoutInflater.createView(LayoutInflater.java:518)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.widget.AbsListView.obtainView(AbsListView.java:1495)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1216)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.widget.ListView.onMeasure(ListView.java:1127)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.view.View.measure(View.java:8335)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.widget.RelativeLayout.measureChild(RelativeLayout.java:566)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:381)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.view.View.measure(View.java:8335)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.view.View.measure(View.java:8335)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.view.View.measure(View.java:8335)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.view.View.measure(View.java:8335)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.view.ViewRoot.performTraversals(ViewRoot.java:843)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1892)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.os.Looper.loop(Looper.java:130)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.app.ActivityThread.main(ActivityThread.java:3835)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at java.lang.reflect.Method.invokeNative(Native Method)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at java.lang.reflect.Method.invoke(Method.java:507)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at dalvik.system.NativeStart.main(Native Method)
08-13 13:26:15.909: E/AndroidRuntime(6832): Caused by: java.lang.reflect.InvocationTargetException
08-13 13:26:15.909: E/AndroidRuntime(6832):     at java.lang.reflect.Constructor.constructNative(Native Method)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.view.LayoutInflater.createView(LayoutInflater.java:505)
08-13 13:26:15.909: E/AndroidRuntime(6832):     ... 32 more
08-13 13:26:15.909: E/AndroidRuntime(6832): Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x2
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.view.View.<init>(View.java:1978)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.widget.TextView.<init>(TextView.java:350)
08-13 13:26:15.909: E/AndroidRuntime(6832):     at android.widget.TextView.<init>(TextView.java:343)
08-13 13:26:15.909: E/AndroidRuntime(6832):     ... 35 more

我设备上的 Android 版本是 2.3.7,模拟器上的版本是 4.0.4 (API 15)

4

2 回答 2

3

您使用的 R.attr 中的所有属性,例如listPreferredItemPaddingLeft,仅在您的设备是姜饼的 Android 14 ( ICS ) 中可用。解决方案:手动设置,尝试几个值,直到一个看起来正确。或者相应地设置 minSDK。

于 2012-08-13T12:02:50.530 回答
1

使用android:id="@+id/text1"代替 android:id="@android:id/text1"

并且...

adapter=new ArrayAdapter<String>(this,R.layout.zalistu,R.id.text1,values);

于 2012-08-13T11:45:31.057 回答