GridView中的ArrayList <integer> </integer>

时间:2014-06-15 12:26:08

标签: gridview arraylist baseadapter

我想通过GridAdapter填充GridView,它扩展了BaseAdapter。 我只找到了教程,他们在其中解释了如何使用a填充GridView 数组列表。我无法为ArrayList执行此操作。

 private static final class GridAdapter extends BaseAdapter {
    final ArrayList<Integer> mItems;
    final int mCount;

    private GridAdapter(final ArrayList<Integer> items){
        mCount = items.size();
        mItems = new ArrayList<Integer>(mCount);
        for (int i = 0; i<=items.size(); i++){
            mItems.add(items.get(i));
        }
    }

    @Override
    public int getCount(){
        return mCount;
    }

    @Override
    public Object getItem(final int position){
        return mItems.get(position);
    }

    @Override
    public long getItemId(final int position){
        return position;
    }

    @Override
    public View getView(final int position, final View convertView, final ViewGroup parent){
        View view = convertView;

        if (view == null){
            view = LayoutInflater.from(parent.getContext()).inflate(android.R.layout.simple_list_item_1, parent, false);
        }

        final TextView text = (TextView) view.findViewById(android.R.id.text1);
        text.setText(mItems.get(position));
        return view;
    }
}

每当我在Android上运行应用时,应用就会关闭。

0 个答案:

没有答案