View Events

splatt

Active Member
Licensed User
Longtime User
Hi Erel,

Just playing around with Basic4Android whilst waiting for my first Android phone.:sign0098:

Is there a list of events for the various view that can be used.

As an example, I have an EditText and would like the existing text to be selected when a user enters the EditText. So, is there the equivalent of EditText.OnEnter where I could SelectAll?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

splatt

Active Member
Licensed User
Longtime User
Thanks for the response.

Android looks an exiting platform. Can't wait to start playing with it for real!
 
Upvote 0

splatt

Active Member
Licensed User
Longtime User
Follow on question

Having read the Views Core link, would I be right in assuming that when a user touches the screen, say over an EditText, that the Activity view first receives a Touch Event, that could be handled?

If so, could one use the GetView Member to identify the child view that was pressed, then as in my example, SelectAll to select any existing text in the EditText view?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Having read the Views Core link, would I be right in assuming that when a user touches the screen, say over an EditText, that the Activity view first receives a Touch Event, that could be handled?
Not exactly. Some views handle the touch event themselves. EditText for example consumes this event.

Focus events for EditText will be added in the next update.
 
Upvote 0

bobsimoneau

Member
Licensed User
Longtime User
Hi Erel,

Just playing around with Basic4Android whilst waiting for my first Android phone.:sign0098:

Is there a list of events for the various view that can be used.

As an example, I have an EditText and would like the existing text to be selected when a user enters the EditText. So, is there the equivalent of EditText.OnEnter where I could SelectAll?

I don't remember where I found the demo that allowed me to program the select all on getting focus of my edittext views. It was attached to the fine Reflection Library. Below is the code I used, and it worked great. Only one reflection object was needed for all four of my edittext views.

Sub Globals
'These global variables will be redeclared each time the activity is created.
Dim edtFat As EditText
Dim edtCarbs As EditText
Dim edtProtein As EditText
Dim edtFiber As EditText
Dim Obj1 As Reflector


Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout1") 'Load the layout file.
Obj1.Target = edtFat
edtFat.Tag = "edtFat"
Obj1.SetOnFocusListener("OnFocus")
Obj1.Target = edtCarbs
edtCarbs.Tag = "edtCarbs"
Obj1.SetOnFocusListener("OnFocus")
Obj1.Target = edtProtein
edtProtein.Tag = "edtProtein"
Obj1.SetOnFocusListener("OnFocus")
Obj1.Target = edtFiber
edtFiber.Tag = "edtFiber"
Obj1.SetOnFocusListener("OnFocus")
edtFat.RequestFocus

End Sub
Sub OnFocus(viewtag As Object, focus As Boolean)
If viewtag = "edtFat" Then edtFat.SelectAll
If viewtag = "edtCarbs" Then edtCarbs.SelectAll
If viewtag = "edtProtein" Then edtProtein.SelectAll
If viewtag = "edtFiber" Then edtFiber.SelectAll
End Sub
 
Last edited:
Upvote 0

splatt

Active Member
Licensed User
Longtime User
Thanks for that Bob. I'll give it a try when I get home.

I haven't come across reflectors before, but I like the concept.
 
Upvote 0

dlfallen

Active Member
Licensed User
Longtime User
Yet another approach is to add a label over the entire EditText view. Then in code you can have:

Sub Label1_Click
EditText1.RequestFocus
EditText1.SelectAll
End Sub

The disadvantage is that the virtual keyboard is not raised. In my case, that's a good thing because I have two programs that I want to raise a custom keyboard instead. I can do that by adding the appropriate code in the Sub Label1_Click subroutine.

Still, I will be glad to get focus events for the EditText view in the next update.
 
Upvote 0

slydog43

Member
Licensed User
Longtime User
Is there a way to force the virtual keyboard to get displayed when a user taps a button (I can switch the focus to an editbox, but I also want the Virtual keyboard to get displayed)
 
Upvote 0
Top