ArrayAdapter没有创建视图

时间:2013-03-20 22:11:44

标签: android android-arrayadapter

我有ArrayAdapter需要填充listView。这是代码

final ArrayAdapter<CarDetails.Extra> aditionalListAdapter = new ArrayAdapter<CarDetails.Extra>(
            this, android.R.layout.simple_list_item_1, CurrentRequest
                    .getCarDetalized().getExtra()) {
        class TagHolder {
            TextView extraName;
            TextView extraPrice;

        }

        @Override
        public View getView(final int position, final View convertView,
                final ViewGroup parent) {
            View v = convertView;
            TagHolder tagHolder = null;
            if (v == null) {
                final LayoutInflater vi = (LayoutInflater) getContext()
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.additional_component, null);

                tagHolder = new TagHolder();
                tagHolder.extraName = (TextView) v
                        .findViewById(R.id.additional_info);
                tagHolder.extraPrice = (TextView) v
                        .findViewById(R.id.additional_price);
                v.setTag(tagHolder);
            } else {
                tagHolder = (TagHolder) v.getTag();
            }
            try {
                final CarDetails.Extra extra = getItem(position);
                tagHolder.extraName.setText(extra.getName());
                tagHolder.extraPrice.setText(extra.getCurrency() + " "
                        + extra.getPrice());
                Log.d("Adapter",
                        "Set up adapter field with name " + extra.getName());

            } catch (final Exception e) {
                e.printStackTrace();
                System.exit(0);
                Log.e("CarList", "Error setting cell" + e);
            }
            return v;
        }

    };
    additionalInfoList.setAdapter(aditionalListAdapter);

getExtra()方法返回带有对象的ArrayList。 LogCat说它有18个对象。它在Android Emulator 4.2.2上正常运行,但它在我的设备4.0.4上不起作用。它只是填充一个(第一个)对象而那个。我尝试重写getCount()方法并将return设置为18,它也没有做任何事情。问题在哪里?

0 个答案:

没有答案