On Sep 7, 2011, at 8:17 AM, Nilesh wrote:
> I wanted to set the SetOnKeyListener on EditText field.
...
> 2) As the SetOnKeyListener requires View.IOnKeyListener.OnKey, I have created
> a another class which implements the OnKey method of the View.IOnKeyListener
> interface as below.
> public class clsKeyListner : View.IOnKeyListener
You need to inherit from Java.Lang.Object to implement the IJavaObject.Handle
property. Failure to do so will be Badâ„¢. :-)
> The above code works fine but I want to call web service when user clicks on
> "Enter" key on virtual keyboard and once I receive the response from web
> service, I want to set it to the List. but I am unable to do it as I am
> calling the web service in the second class and how to set that response in
> the layout which is present in the first activity class.
Alter your clsKeyListner type to take an Activity as a constructor parameter,
and use the provided Activity with subsequent FindViewById() calls:
class clsKeyListner : Java.Lang.Object, View.IOnKeyListener {
public clsKeyListner (Activity activity)
{
this.activity = activity;
}
private Activity activity;
bool View.IOnKeyListener.OnKey(View v, int keyCode, KeyEvent e)
{
if (e.Action == KeyEventActions.Down && keyCode ==
(int) Keycode.Enter) {
activity.FindViewById<EditText>(Resource.Id.txtSearch).Text = "updated value!";
return isEnterKeyPressed = true;
}
return false;
}
}
- Jon
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid