Я хочу использовать ItemAdapter GreenDroid и пользовательские элементы списка с обычным ListActivity (или в будущем в SherlockListActivity). Я извлек классы ItemAdapter, Item и View и создал собственный проект. (Примечание: вчера я пытался сделать то же самое, используя весь проект GreenDroid. Таким образом, нет проблем с моим новым извлеченным проектом)
Мой пример ListActivity:
public class TestActivity extends ListActivity {
/** Called when the activity is first created. */
ItemAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapter=new ItemAdapter(this);
adapter.add(new TextItem("test"));
adapter.notifyDataSetChanged();
setListAdapter(adapter);
}
}
вылетает и выдает следующее:
01-30 17:07:33.983: E/AndroidRuntime(21042): FATAL EXCEPTION: main
01-30 17:07:33.983: E/AndroidRuntime(21042): android.view.InflateException: Binary XML file line #20: Error inflating class com.itusozluk.itemadapter.widget.itemview.TextItemView
01-30 17:07:33.983: E/AndroidRuntime(21042): at android.view.LayoutInflater.createView(LayoutInflater.java:606) 01-30
17:07:33.983: E/AndroidRuntime(21042): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
01-30 17:07:33.983: E/AndroidRuntime(21042): at android.view.LayoutInflater.inflate(LayoutInflater.java:466) 01-30
17:07:33.983: E/AndroidRuntime(21042): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 01-30
17:07:33.983: E/AndroidRuntime(21042): at com.itusozluk.itemadapter.widget.item.Item.createCellFromXml(Item.java:125)
01-30 17:07:33.983: E/AndroidRuntime(21042): at com.itusozluk.itemadapter.widget.item.TextItem.newView(TextItem.java:61)
01-30 17:07:33.983: E/AndroidRuntime(21042): at com.itusozluk.itemadapter.ItemAdapter.getView(ItemAdapter.java:445)
01-30 17:07:33.983: E/AndroidRuntime(21042): at android.widget.AbsListView.obtainView(AbsListView.java:2033) 01-30
17:07:33.983: E/AndroidRuntime(21042): at android.widget.ListView.makeAndAddView(ListView.java:1772) 01-30
17:07:33.983: E/AndroidRuntime(21042): at android.widget.ListView.fillDown(ListView.java:672) 01-30
17:07:33.983: E/AndroidRuntime(21042): at android.widget.ListView.fillFromTop(ListView.java:732) 01-30
17:07:33.983: E/AndroidRuntime(21042): at android.widget.ListView.layoutChildren(ListView.java:1625) 01-30
17:07:33.983: E/AndroidRuntime(21042): at android.widget.AbsListView.onLayout(AbsListView.java:1863) 01-30
17:07:33.983: E/AndroidRuntime(21042): at android.view.View.layout(View.java:11278) 01-30 17:07:33.983:
E/AndroidRuntime(21042): at android.view.ViewGroup.layout(ViewGroup.java:4224) 01-30 17:07:33.983:
E/AndroidRuntime(21042): at android.widget.FrameLayout.onLayout(FrameLayout.java:431) 01-30
17:07:33.983: E/AndroidRuntime(21042): at android.view.View.layout(View.java:11278) 01-30 17:07:33.983:
E/AndroidRuntime(21042): at android.view.ViewGroup.layout(ViewGroup.java:4224) 01-30 17:07:33.983:
E/AndroidRuntime(21042): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
01-30 17:07:33.983: E/AndroidRuntime(21042): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
01-30 17:07:33.983: E/AndroidRuntime(21042): at android.widget.LinearLayout.onLayout(LinearLayout.java:1399) 01-30
17:07:33.983: E/AndroidRuntime(21042): at android.view.View.layout(View.java:11278) 01-30 17:07:33.983:
E/AndroidRuntime(21042): at android.view.ViewGroup.layout(ViewGroup.java:4224) 01-30 17:07:33.983:
E/AndroidRuntime(21042): at android.widget.FrameLayout.onLayout(FrameLayout.java:431) 01-30
17:07:33.983: E/AndroidRuntime(21042): at android.view.View.layout(View.java:11278) 01-30 17:07:33.983:
E/AndroidRuntime(21042): at android.view.ViewGroup.layout(ViewGroup.java:4224) 01-30 17:07:33.983:
E/AndroidRuntime(21042): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489)
01-30 17:07:33.983: E/AndroidRuntime(21042): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442) 01-30
17:07:33.983: E/AndroidRuntime(21042): at android.os.Handler.dispatchMessage(Handler.java:99) 01-30
17:07:33.983: E/AndroidRuntime(21042): at android.os.Looper.loop(Looper.java:137) 01-30 17:07:33.983:
E/AndroidRuntime(21042): at android.app.ActivityThread.main(ActivityThread.java:4424) 01-30
17:07:33.983: E/AndroidRuntime(21042): at java.lang.reflect.Method.invokeNative(Native Method) 01-30
17:07:33.983: E/AndroidRuntime(21042): at java.lang.reflect.Method.invoke(Method.java:511) 01-30 17:07:33.983:
E/AndroidRuntime(21042): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
01-30 17:07:33.983: E/AndroidRuntime(21042): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554) 01-30
17:07:33.983: E/AndroidRuntime(21042): at dalvik.system.NativeStart.main(Native Method) 01-30 17:07:33.983:
E/AndroidRuntime(21042): Caused by: java.lang.reflect.InvocationTargetException 01-30 17:07:33.983:
E/AndroidRuntime(21042): at java.lang.reflect.Constructor.constructNative(Native Method) 01-30
17:07:33.983: E/AndroidRuntime(21042): at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 01-30
17:07:33.983: E/AndroidRuntime(21042): at android.view.LayoutInflater.createView(LayoutInflater.java:586) 01-30
17:07:33.983: E/AndroidRuntime(21042): ... 35 more 01-30
17:07:33.983: E/AndroidRuntime(21042): Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x2
01-30 17:07:33.983: E/AndroidRuntime(21042): at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
01-30 17:07:33.983: E/AndroidRuntime(21042): at android.view.View.<init>(View.java:2791) 01-30 17:07:33.983:
E/AndroidRuntime(21042): at android.widget.TextView.<init>(TextView.java:449) 01-30 17:07:33.983:
E/AndroidRuntime(21042): at com.itusozluk.itemadapter.widget.itemview.TextItemView.<init>(TextItemView.java:36)
01-30 17:07:33.983: E/AndroidRuntime(21042): at com.itusozluk.itemadapter.widget.itemview.TextItemView.<init>(TextItemView.java:32)
01-30 17:07:33.983: E/AndroidRuntime(21042): ... 38 more
Я думаю, что самая важная часть:
java.lang.UnsupportedOperationException: Can't convert to dimension:
type=0x2 01-30 17:07:33.983: E/AndroidRuntime(21042):
В файлах измерений GreenDroid должно быть что-то.
Как исправить? Как можно использовать ItemAdapter GreenDroid без GDActivity?