【发布时间】:2014-02-05 12:21:28
【问题描述】:
我必须为 MvxGridView 实现一个自定义适配器。
这个适配器应该根据绑定的类型,膨胀一个视图,并设置一个图像资源。
我可以只覆盖 MvxAdapter 中的 GetView 吗?
public override View GetView(int position, View convertView, ViewGroup parent)
{
var inflater = (LayoutInflater)this.Context.GetSystemService(Context.LayoutInflaterService);
var productNode = (ProductNode)this.GetRawItem(position);
if (productNode.NodeType == ProductNodeType.Folder)
{
return inflater.Inflate(Resource.Layout.GridFolderItem, parent);
}
else
{
View documentItemView = inflater.Inflate(Resource.Layout.GridDocumentItem, parent);
var imageView = documentItemView.FindViewById<MvxImageView>(Resource.Layout.GridFolderItem);
switch (productNode.NodeType)
{
case ProductNodeType.Unknown:
throw new InvalidOperationException("Node type hasn't been initialized");
case ProductNodeType.Image:
// Set matching image
break;
case ProductNodeType.Pdf:
break;
case ProductNodeType.Parts:
break;
default:
throw new InvalidOperationException(
string.Format("Unhandled node type '{0}'", productNode.NodeType));
}
return imageView;
}
}
或者我应该覆盖 GetBindableView 吗?
在这种情况下,如果没有父 ViewGroup,我真的不知道如何处理通货膨胀......
【问题讨论】: