public override void OnBindSwipeContentHolder(ListViewHolder holder, int position)
嗨朋友我正在使用 Telerik UI for android Controls 开发 Android 应用程序请帮助我“OnBindSwipeContentHolder”未找到错误我该如何解决这个问题。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Com.Telerik.Widget.List;
using Android.Support.V7.Widget;
using System.Collections;
namespace test
{
public class TelerikListView : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.ListView);
// Create your application here
RadListView listview = FindViewById<RadListView>(Resource.Id.listView);
ListViewAdapter adapter = new ListViewAdapter(GetListOfCities());
listview.SetAdapter(adapter);
//CityAdapter adapterlist = new CityAdapter(GetListOfCities());
//listview.SetAdapter(adapterlist);
SelectionBehavior selectionBehavior = new SelectionBehavior();
listview.AddBehavior(selectionBehavior);
selectionBehavior.SetSelectionMode(SelectionBehavior.SelectionMode.Single);
SelectionListener selectionListener = new SelectionListener(this, selectionBehavior);
selectionBehavior.AddListener(selectionListener);
SwipeExecuteBehavior swipeExecuteBehavior = new SwipeExecuteBehavior();
listview.AddBehavior(swipeExecuteBehavior);
SwipeExecuteListener swipeExecuteListener = new SwipeExecuteListener(adapter);
swipeExecuteBehavior.AddListener(swipeExecuteListener);
swipeExecuteBehavior.SwipeLimitStart = -50;
swipeExecuteBehavior.SwipeLimitEnd = 50;
}
private List<City> GetListOfCities()
{
List<City> cities = new List<City>();
cities.Add(new City("London", "United Kingdom"));
cities.Add(new City("Berlin", "Germany"));
cities.Add(new City("Madrid", "Spain"));
cities.Add(new City("Rome", "Italy"));
cities.Add(new City("Paris", "France"));
cities.Add(new City("Hamburg", "Germany"));
cities.Add(new City("Barcelona", "Spain"));
cities.Add(new City("Munich", "Germany"));
cities.Add(new City("Milan", "Italy"));
cities.Add(new City("Cologne", "Germany"));
return cities;
}
public override void OnBindSwipeContentHolder(ListViewHolder holder, int position)
{
RelativeLayout mainLayout = (RelativeLayout)holder.ItemView;
LinearLayout leftLayout = (LinearLayout)mainLayout.GetChildAt(0);
LinearLayout rightLayout = (LinearLayout)mainLayout.GetChildAt(1);
Button leftButton = new Button(mainLayout.Context);
leftButton.Text = "edit";
Button rightButton = new Button(mainLayout.Context);
rightButton.Text = "delete";
leftLayout.RemoveAllViews();
leftLayout.AddView(leftButton);
rightLayout.RemoveAllViews();
rightLayout.AddView(rightButton);
}
}
public class CityAdapter : ListViewAdapter
{
public CityAdapter(IList items)
: base(items)
{
}
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{
LayoutInflater inflater = LayoutInflater.From(parent.Context);
View view = inflater.Inflate(Resource.Layout.city_list_item, parent, false);
return new CityViewHolder(view);
}
public override void OnBindListViewHolder(ListViewHolder holder, int position)
{
CityViewHolder viewHolder = (CityViewHolder)holder;
City city = (City)Items[position];
viewHolder.nameView.Text = city.Name;
viewHolder.countryView.Text = city.Country;
}
public class CityViewHolder : ListViewHolder
{
public TextView nameView;
public TextView countryView;
public CityViewHolder(View itemView)
: base(itemView)
{
nameView = (TextView)itemView.FindViewById(Resource.Id.nameView);
countryView = (TextView)itemView.FindViewById(Resource.Id.countryView);
}
}
}
public class SelectionCallback : Java.Lang.Object, ActionMode.ICallback
{
private SelectionBehavior selectionBehavior;
public SelectionCallback(SelectionBehavior behavior)
{
selectionBehavior = behavior;
}
public bool OnCreateActionMode(ActionMode mode, IMenu menu)
{
MenuInflater inflater = mode.MenuInflater;
inflater.Inflate(Resource.Menu.menu_main, menu);
return true;
}
public bool OnPrepareActionMode(ActionMode mode, IMenu menu)
{
return false;
}
public bool OnActionItemClicked(ActionMode mode, IMenuItem item)
{
return false;
}
public void OnDestroyActionMode(ActionMode mode)
{
selectionBehavior.EndSelection();
}
}
public class SelectionListener : Java.Lang.Object,
SelectionBehavior.ISelectionChangedListener
{
private ActionMode actionMode;
private ActionMode.ICallback callback;
private Activity activity;
private SelectionBehavior selectionBehavior;
public SelectionListener(Activity activity, SelectionBehavior selectionBehavior)
{
this.callback = new SelectionCallback(selectionBehavior);
this.activity = activity;
this.selectionBehavior = selectionBehavior;
}
public void OnSelectionStarted()
{
actionMode = activity.StartActionMode(callback);
}
public void OnItemIsSelectedChanged(int position, bool newValue)
{
int selectionCount = selectionBehavior.SelectedItems().Count;
actionMode.Title = selectionCount.ToString();
}
public void OnSelectionEnded()
{
actionMode.Finish();
}
}
/// <summary>
/// Swiping behaviour
/// </summary>
public class SwipeExecuteListener : Java.Lang.Object, SwipeExecuteBehavior.ISwipeExecuteListener
{
private ListViewAdapter listViewAdapter;
public SwipeExecuteListener(ListViewAdapter adapter)
{
listViewAdapter = adapter;
}
public void OnSwipeStarted(int position)
{
}
public void OnSwipeProgressChanged(int position, int offset, View swipeContent)
{
}
public void OnSwipeEnded(int position, int offset)
{
int absOffset = Math.Abs(offset);
if (absOffset > 300)
{
listViewAdapter.Remove(position);
}
listViewAdapter.NotifySwipeExecuteFinished();
}
public void OnExecuteFinished(int position)
{
}
}
}