如何从ListView项目获取ImageView?

时间:2011-08-08 12:25:55

标签: java android listview imageview

我有一个列表活动,我希望将图像资源设置为列表视图项目中的图像视图。

        ListView listView = getListView();
        View view = listView.getChildAt(0);
        arrowImageView = (ImageView)view.findViewById(R.id.arrowImageView);

但getChildAt(0)返回null。列表有10个项目。 我怎么能找到一个ImageView?

1 个答案:

答案 0 :(得分:0)

修改
我想你问的是如何在列表视图的每个项目中设置图像资源?如果是这样,请扩展SimpleCursorAdapter并覆盖getView,类似于:

// Create the list adapter
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
        CfsApplication.getApplication(),
        R.layout.listitem_vehicledraft,
        VehicleDraftTable.getAllVehicleDrafts(),
        displayFields,
        displayViews) {
    /* (non-Javadoc)
     * @see android.widget.CursorAdapter#getView(int, android.view.View, android.view.ViewGroup)
     */
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        // Get the view from the super function which will handle most of everthing for us
        convertView = super.getView(position, convertView, parent);

        // Set the image view here
                    // ...

        // Return the view
        return convertView;
    }
};