无法将CustomAdapter表达式转换为在xamarin android

时间:2016-04-20 22:29:10

标签: xamarin xamarin.android



string[] items = new string[] { "Alternative Rock","Classical", "Country"}






for (int i = 0; i <= items.Count(); i++) {
				mAdapter.addItem (items [i].ToString ());
				if (i == 0) {
					mAdapter.addSectionHeaderItem ("Music");
				} else if(i==13) {
					mAdapter.addSectionHeaderItem ("Audio");
				}
			}
			lst.Adapter = new CustomAdapter (Activity, mAdapter);
&#13;
&#13;
&#13;

&#13;
&#13;
public class CustomAdapter : BaseAdapter{

	private  const int TYPE_ITEM = 0;
	private const int TYPE_SEPARATOR = 1;

	private List<string> mData;
	private TreeSet sectionHeader;

	private LayoutInflater mInflater;

	public CustomAdapter(Context context, List<string> mData) {
		mInflater = (LayoutInflater) context
			.GetSystemService(Context.LayoutInflaterService);
		this.mData=mData;
	}

	public void addItem( string item) {
		mData.Add(item);
		NotifyDataSetChanged();
	}

	public void addSectionHeaderItem(string item) {
		mData.Add(item);
		sectionHeader.Add(mData.Count - 1);
		NotifyDataSetChanged();
	}

	public int getItemViewType(int position) {
		return sectionHeader.Contains(position) ? TYPE_SEPARATOR : TYPE_ITEM;
	}


	public int getViewTypeCount {
		get{ return 2; }
	}


	public override int Count {
		get {return mData.Count;}
	}


	public override Java.Lang.Object GetItem(int position) {
		return null;
	}
		
	public override long GetItemId(int position) {
		return position;
	} 

	public View GetView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		int rowType = getItemViewType(position);

		if (convertView == null) {
			holder = new ViewHolder();
			switch (rowType) {
			case TYPE_ITEM:
				convertView = mInflater.Inflate(Resource.Layout.textViewItemsSeparator, parent);
				holder.textView = (TextView) convertView.FindViewById(Resource.Id.textviewHeaderItems);
				break;
			case TYPE_SEPARATOR:
				convertView = mInflater.Inflate(Resource.Layout.textViewHeaderItems, parent);
				holder.textView = (TextView) convertView.FindViewById(Resource.Id.textviewItemsSeparator);
				break;
			}
			convertView.Tag=holder;
		} else {
			holder = (ViewHolder)convertView.Tag as ViewHolder;
		}
		holder.textView.Text=mData[position];

		return convertView;
	}

	public  class ViewHolder:Java.Lang.Object {
		public TextView textView;
	}
&#13;
&#13;
&#13;

无法将CustomAdapter表达式转换为xamarin android上的System.Collections.Generic.List类型

  

CustomAdapter:BaseAdapter和新的CustomAdapter(活动,   mAdapter);   块引用

在此示例中,我们将展示如何使用节头创建ListView。这涉及以下步骤

更新我的帖子。

1 个答案:

答案 0 :(得分:0)

CustomAdapter构造函数的签名指定两个参数,即上下文和List<string>

public CustomAdapter(Context context, List<String> mData) {

但是,当您创建它时,您将传递mAdapter作为第二个参数而不是List<string>

lst.Adapter = new CustomAdapter (Activity, mAdapter);