Last active
January 3, 2016 07:59
-
-
Save prashantvc/8432871 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using Android.App; | |
using Android.Views; | |
using Android.Widget; | |
using R = ClickEvents.Resource; | |
using Android.Text; | |
using System; | |
namespace ClickEvents | |
{ | |
public class MyAdapter : BaseAdapter<TableItem> | |
{ | |
Activity context; | |
List<TableItem> items; | |
public MyAdapter (Activity context, List<TableItem> items) | |
: base () | |
{ | |
this.items = items; | |
this.context = context; | |
} | |
public override Java.Lang.Object GetItem (int position) | |
{ | |
return items [position]; | |
} | |
public override int Count { | |
get { | |
return items.Count; | |
} | |
} | |
public override long GetItemId (int position) | |
{ | |
return position; | |
} | |
public override View GetView (int position, View convertView, ViewGroup parent) | |
{ | |
var item = items [position]; | |
ViewHolder holder; | |
View view = convertView; | |
EditText editText; | |
if (view == null) { | |
view = context.LayoutInflater.Inflate (R.Layout.CustomView, null); | |
holder = new ViewHolder (); | |
editText = view.FindViewById<EditText> (R.Id.editText); | |
editText.Tag = position; | |
holder.MyEditText = editText; | |
holder.MyEditText.AddTextChangedListener (new TextHandler (editText, (ListView)parent)); | |
view.Tag = holder; | |
} else { | |
holder = (ViewHolder)view.Tag; | |
} | |
editText = holder.MyEditText; | |
editText.Text = item.Title; | |
return view; | |
} | |
public override TableItem this [int index] { | |
get { | |
return items [index]; | |
} | |
} | |
} | |
public class ViewHolder : Java.Lang.Object | |
{ | |
public EditText MyEditText { | |
get; | |
set; | |
} | |
} | |
class TextHandler : Java.Lang.Object, ITextWatcher | |
{ | |
readonly EditText view; | |
readonly ListView list; | |
public TextHandler (EditText view, ListView list) | |
{ | |
this.list = list; | |
this.view = view; | |
} | |
public void AfterTextChanged (IEditable s) | |
{ | |
//Console.WriteLine ("After text changed: {0}, View.Text: {1}", position, view.Text); | |
} | |
public void BeforeTextChanged (Java.Lang.ICharSequence s, int start, int count, int after) | |
{ | |
//Console.WriteLine ("Before text changed: {0}, View.Text:{1}", position, view.Text); | |
} | |
public void OnTextChanged (Java.Lang.ICharSequence s, int start, int before, int count) | |
{ | |
var item = list.FindViewWithTag (view.Tag); | |
if (item == null) { | |
return; | |
} | |
int p = list.GetPositionForView (view); | |
Console.WriteLine ("Text changed: {0}, View.Text: {1}", p, view.Text); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment