0

我有一个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()方法并将返回设置为 18,它也没有做任何事情。问题出在哪里?

4

0 回答 0