开发者

How get ImageView from ListView item?

I have a list Activity and I want set image resource to Image view in list view item.

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

but getChild开发者_开发知识库At(0) return null. List have 10 items. How i can find a ImageView?


Edit
I think you're asking how to set an image resource in each item of your list view? If so, extend your SimpleCursorAdapter and override getView similar to this:

// 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;
    }
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜