[英]How get ImageView from ListView item?
我有一个列表活动,我想将图像资源设置为列表视图项中的图像视图。
ListView listView = getListView();
View view = listView.getChildAt(0);
arrowImageView = (ImageView)view.findViewById(R.id.arrowImageView);
但是getChildAt(0)返回null。 清单有10个项目。 我如何找到ImageView?
编辑
我想您是在问如何在列表视图的每个项目中设置图像资源? 如果是这样,请扩展您的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;
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.