So i have four different entries, which acts as a pin input holder, and what i'm trying to do is , basically each entry when backspace is pressed should go to the previous entry considering the entry on which the backspace was pressed is empty.
I tried doing it in Renderer but it doesn't fire anything when its empty, same goes for TextChanged
What i was trying to do was a small hack ,where in i tried to put " ", that is a space in all the entries while initializing, and when a user tried to put something i would check the old value and new value, and replace it, but the problem seems to be when i navigate to the second entry and lets say i press backspace, then the i should be able to go the first entry which is something i'm not able to figure out how
below is a small snippet of what i was trying to do, but it has some issues, any inputs would be helpful
private void secondEntry_TextChanged(object sender, TextChangedEventArgs e)
{
if (e.OldTextValue == null && !e.NewTextValue.Equals(" "))
{
Entry_Second.Text = e.NewTextValue;
Entry_Third.Focus();
}
else if (e.NewTextValue == "")
{
Entry_Second.Text = " ";
}
else
{
Entry_Second.Focus();
}
}
In Xamarin.Android , you can try to handle the edit text key press event. Keycode is Keycode.Back when the delete button is pressed on a keyboard and handle the event accordingly.
In Xamarin.iOS
You can try overriding the DeleteBackward method in the custom text field (BackDeleteEventTextField) and call a custom event OnDeleteBackwardKeyPressed.
In the custom renderer you can override the text field with your custom text field in on element changed method
and handle the custom event OnDeleteBackwardKeyPressed
In Xamarin.Android :
In the custom renderer you can handle the key press event and look for the Keycode.Back
};
Update
Elaborating for xamarin.iOS using forms.
Step 1: Create a custom entry class and create a delegate to handle the back button press
Step 2 :Within the custom renderer namespace , create a custom text field class.
Step 3: Within the custom text field, create a event and delegate to handle the delete button click.
Step 4 :Within the custom renderer name space, Create custom renderer class.
Step 5:Within the custom renderer's OnElementChanged method create a text field of the custom text field type.
Step 6: Handle the custom text field delete event by passing it to the custom entry back button event handler.
Step 7: Assign the custom text field object to native control.
step 8 : Add the editing changed handler