gpt4 book ai didi

android - 如何创建带有部分标题的 Android ListView xamarin android?我有 17 个错误

转载 作者:行者123 更新时间:2023-11-30 01:24:03 26 4
gpt4 key购买 nike

在此示例中,我们将展示如何创建带有节标题的 ListView。这涉及以下步骤

为您的列表标题和列表行创建两个自定义布局为 ListView 创建自定义适配器在您的 Activity 中实例化 ListView

我有 17 个错误。我想用节头 xamarin android 创建 ListView 。 http://javatechig.com/android/listview-with-section-header-in-android

我从java转换成C#

>  - `public class CustomAdapter:BaseAdapter`->does not implement abstract member `android.widget.baseAdapter.getitem(int)`
> - `Android.Widget.BaseAdapter.NotifyDataSetChanged ()`-> An object reference is requered to access non-static member .....
> - `return mData.GetRange(position)`;-> no overload for method 'getrange'take 1 arguments
> - `convertView = mInflater.Inflate(Resource.Layout.textViewHeaderItems, false)`;-> the
> best overloaded method match for ..... has some invalid arguments
> - `convertView.SetTag(holder);`-> no overload for method ... tkae 2 arguments
> - `holder.textView.SetText(mData.get(position))`; type system.collection.generic.list<string> does not contain a defintion
> for 'get'and no extension method 'get'of type
> `system.Colleciton.Generic.List<string>` could be found. Are you
> missing an assembly

public class CustomAdapter:BaseAdapter
{
private const int TYPE_ITEM = 0;
private const int TYPE_SEPARATOR = 1;

private List<String> mData = new List<String>();
private TreeSet sectionHeader = new TreeSet();

private LayoutInflater mInflater;

public CustomAdapter(Context context) {
mInflater = (LayoutInflater) context
.GetSystemService(Context.LayoutInflaterService);
}

public void addItem(String item) {
mData.Add(item);
Android.Widget.BaseAdapter.NotifyDataSetChanged ();
}

public void addSectionHeaderItem(String item) {
mData.Add(item);
sectionHeader.Add(mData.Count - 1);
Android.Widget.BaseAdapter.NotifyDataSetChanged ();
}


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


public int getViewTypeCount() {
return 2;
}


public int getCount() {
return mData.Count;
}


public String getItem(int position) {
return mData.GetRange(position);
}


public 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.textViewHeaderItems, false);
holder.textView = (TextView) convertView.FindViewById(Resource.Id.textviewHeaderItems);
break;
case TYPE_SEPARATOR:
convertView = mInflater.Inflate(Resource.Layout.textViewItemsSeparator, false);
holder.textView = (TextView) convertView.FindViewById(Resource.Id.textviewItemsSeparator);
break;
}
convertView.SetTag(holder);
} else {
holder = (ViewHolder) convertView.GetTag();
}
holder.textView.SetText(mData.get(position));

return convertView;
}

public class ViewHolder {
public TextView textView;
}
}

最佳答案

您应该使用 Xamarin 开发站点上的“搜索”功能来解决以下问题:

注意:对于此类问题,Google 或 Bing 也是您最好的 friend 。

Android.Content.Context.LayoutInflaterService

Use with Context.GetSystemService(String) to retrieve a LayoutInflater for inflating layout resources in this context.

https://developer.xamarin.com/api/field/Android.Content.Context.LayoutInflaterService/

Android.Widget.BaseAdapter.NotifyDataSetChanged

Notifies the attached observers that the underlying data has been changed and any View reflecting the data set should refresh itself.

https://developer.xamarin.com/api/member/Android.Widget.BaseAdapter.NotifyDataSetChanged/

Java.Util.TreeSet

TreeSet is an implementation of SortedSet.

https://developer.xamarin.com/api/type/Java.Util.TreeSet/

关于android - 如何创建带有部分标题的 Android ListView xamarin android?我有 17 个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36685330/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com