i am currently working with recyclerview in Xamarin android where i wish to filter the data displayed. I used to work with java on android and has successfully create a filter on recyclerview with using searchview. But for this one , i wish to display only the incomplete data where either one of the item in the view is empty. Below is my code for activity class and also recyclerview adapter class.Replies with code or explanation would be really helpful. Thank you.
class RemoveAlertActivity : Activity
{
private RecyclerView mRecyclerView_remove;
private RecyclerView.LayoutManager mLayoutManager_remove;
private RecyclerView.Adapter mAdapter_remove;
private List<Removerecyclerholder> mRemoverecyclerholder;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.RemoveAlert);
SQLiteDb obj = new SQLiteDb();
List<ScanSummary> scan = new List<ScanSummary>();
scan = obj.GetAllScanSummaryData();
ScanSummary[] array = scan.ToArray();
mRemoverecyclerholder = new List<Removerecyclerholder>();
for (int i = 0; i < array.Length; i++)
{
mRemoverecyclerholder.Add(new Removerecyclerholder() { partnumber_r = scan[i].SSPartNo, containernumber_r = scan[i].SSContainerSN, scanquantity_r = scan[i].SSPackType, totalquantity_r = scan[i].SSStatus });
}
mRecyclerView_remove = FindViewById<RecyclerView>(Resource.Id.recyclerview_remove);
mLayoutManager_remove = new LinearLayoutManager(this);
mRecyclerView_remove.SetLayoutManager(mLayoutManager_remove);
mAdapter_remove = new RecyclerAdapter_remove(mRemoverecyclerholder);
mRecyclerView_remove.SetAdapter(mAdapter_remove);
}
}
public class RecyclerAdapter_remove : RecyclerView.Adapter
{
private List<Removerecyclerholder> mRemoverecyclerholder;
public RecyclerAdapter_remove(List<Removerecyclerholder> removerecyclerholder)
{
mRemoverecyclerholder = removerecyclerholder;
}
public class MyView : RecyclerView.ViewHolder
{
public View mMainView { get; set; }
public TextView mpartnumber_r { get; set; }
public TextView mcontainernumber_r { get; set; }
public TextView mtotalquantity_r { get; set; }
public TextView mscanquantity_r { get; set; }
public MyView(View view) : base(view)
{
mMainView = view;
}
}
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{
SQLiteDb obj = new SQLiteDb();
List<ScanSummary> scan = obj.GetAllScanSummaryData();
View RemoveRecycleLayout = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.RemoveAlertRecycleLayout, parent, false);
TextView txtpartnumber_r = RemoveRecycleLayout.FindViewById<TextView>(Resource.Id.partnumber_remove);
TextView txtcontainernumber_r = RemoveRecycleLayout.FindViewById<TextView>(Resource.Id.containernumber_remove);
TextView txttotalquantity_r = RemoveRecycleLayout.FindViewById<TextView>(Resource.Id.totalquantity_remove);
TextView txtscanquantity_r = RemoveRecycleLayout.FindViewById<TextView>(Resource.Id.scanquantity_remove);
MyView view = new MyView(RemoveRecycleLayout) { mpartnumber_r = txtpartnumber_r, mcontainernumber_r = txtcontainernumber_r, mtotalquantity_r = txttotalquantity_r, mscanquantity_r = txtscanquantity_r };
return view;
}
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
MyView myholder = holder as MyView;
myholder.mpartnumber_r.Text = mRemoverecyclerholder[position].partnumber_r;
myholder.mcontainernumber_r.Text = mRemoverecyclerholder[position].containernumber_r;
myholder.mtotalquantity_r.Text = mRemoverecyclerholder[position].totalquantity_r;
myholder.mscanquantity_r.Text = mRemoverecyclerholder[position].scanquantity_r;
((MyView)holder).mMainView.Click += delegate (object sender, EventArgs e)
{
View mMainView = (View)sender;
mMainView.SetBackgroundColor(color: Color.Blue);
var activity = new Intent(Application.Context, typeof(RemoveDataDetails));
activity.PutExtra("partnumber_r", mRemoverecyclerholder[position].partnumber_r);
activity.PutExtra("containernumber_r", mRemoverecyclerholder[position].containernumber_r);
Application.Context.StartActivity(activity);
};
}
public override int ItemCount
{
get { return mRemoverecyclerholder.Count; }
}
}