Tab order of textedit views

ukimiku

Active Member
Licensed User
Longtime User
Is there a way to control (in code or in the Designer) the order in which the user "forwards" (by pressing the "next" button in the edittext edit window that opens) through the different edittext views on a form?

Thank you.

Regards,
 

mc73

Well-Known Member
Licensed User
Longtime User
I think you can use the tag property of your text boxes, or an array containing the tab order. Then you should check for the next tab position, when the 'enter_pressed' event is triggered, and then setting focus to the corresponding text box.
 
Upvote 0

ukimiku

Active Member
Licensed User
Longtime User
Thank you, I will try that. At the moment, the "tag" property is indeed unused with my edittext views.

Regards,
 
Upvote 0

deantangNYP

Active Member
Licensed User
Longtime User
Tab Order

Is there a "Tab Order" feature in b4a which is similar to VB?
if there is none, whats the best method to navigate from one EditText to another? sample code would be appreciated.

Thanks. Newbie
:sign0085::sign0163:
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
- Set ForceDone of all the EditTexts to True.
- Set their EventName to EditText

Use the tag property to set the next EditText:
B4X:
EditText1.Tag = EditText2
EditText2.Tag = EditText3
EditText3.Tag = EditText4
EditText4.Tag = EditText1

Sub EditText_EnterPressed
   Dim currentView, nextView As View
   currentView = Sender
   nextView = currentView.Tag
   nextView.RequestFocus
End Sub
 
Upvote 0

deantangNYP

Active Member
Licensed User
Longtime User
Tried the code, but got an error "....java.lang.string cannot be cast to android.view...." Did i miss something?
Thanks.
Attachin the code.
:sign0085:

- Set ForceDone of all the EditTexts to True.
- Set their EventName to EditText

Use the tag property to set the next EditText:
B4X:
EditText1.Tag = EditText2
EditText2.Tag = EditText3
EditText3.Tag = EditText4
EditText4.Tag = EditText1

Sub EditText_EnterPressed
   Dim currentView, nextView As View
   currentView = Sender
   nextView = currentView.Tag
   nextView.RequestFocus
End Sub
 
Upvote 0

deantangNYP

Active Member
Licensed User
Longtime User
I thought the remark from Erel "Use the tag property to set the next EditText" is to set the TAG property (in the designer window) as shown in the jpg image in the attach.
Is it still required to set the TAG PROPERTY? or Both (source code And property/designer window) ?

Thanks for the support.
 

Attachments

  • tag.JPG
    tag.JPG
    30.1 KB · Views: 310
Upvote 0

klaus

Expert
Licensed User
Longtime User
In this case you don't need to specify the Tag property in the Designer because you change it afterwards in the code.
I suppose that the Tag properties set in the Designer is considered as Strings and not as objects thats the reason why you need to define them in the code.

Best regards.
 
Upvote 0

deantangNYP

Active Member
Licensed User
Longtime User
Many Thanks.

In this case you don't need to specify the Tag property in the Designer because you change it afterwards in the code.
I suppose that the Tag properties set in the Designer is considered as Strings and not as objects thats the reason why you need to define them in the code.

Best regards.
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
- Set ForceDone of all the EditTexts to True.
- Set their EventName to EditText

Use the tag property to set the next EditText:
B4X:
EditText1.Tag = EditText2
EditText2.Tag = EditText3
EditText3.Tag = EditText4
EditText4.Tag = EditText1

Sub EditText_EnterPressed
   Dim currentView, nextView As View
   currentView = Sender
   nextView = currentView.Tag
   nextView.RequestFocus
End Sub

I am using the above in my code with some modifications.

Instead of setting the tag to another field, I set it to and Type
B4X:
Type  sETInfo(FieldName As String, Field As EditText, NextTab As EditText)
I set the fields in the type properly and modified the Enter_Pressed to handled it.

I am having two problems. My last field when clicking on Done does not go to the first field and the First field ALWAYS gets the data from the previous field (does not show on screen) but is in the actual field.

I am really lost on this one.

All the fields are marked as Force Done = True

Here is the code where I set the Tab order
B4X:
'    Type  sETInfo(FieldName As String, Field As EditText, NextTab As EditText)  '  <-- this is defined in global section just copied here  

Sub SetTabOrder(FieldName As String, Field As EditText, NextTab As EditText)

	Dim ETInfo		As sETInfo
	
	ETInfo.Initialize
	ETInfo.FieldName	= FieldName
	ETInfo.Field		= Field
	ETInfo.NextTab		= NextTab
	
	Field.Tag			= ETInfo
End Sub

Sub SetupFields
	mFWC_FWName.Color 			= Colors.White
	
	mFWC_StartsAtGame.Color 	= Colors.White	
	mFWC_NumberOfGames.Color 	= Colors.White
	
	mFWC_Cost.Color			 	= Colors.White
	
	mFWC_HandicapBase.Color 	= Colors.White	
	mFWC_HandicapPercent.Color 	= Colors.White
	
	mFWC_BonusPins.Color 		= Colors.White
	
	'-------------------------------------------------------
	'  Set TabOrder
	'-------------------------------------------------------
	SetTabOrder("mFWC_FWName",			mFWC_FWName,			mFWC_StartsAtGame)
	SetTabOrder("mFWC_StartsAtGame",	mFWC_StartsAtGame,		mFWC_NumberOfGames)
	SetTabOrder("mFWC_NumberOfGames",	mFWC_NumberOfGames,		mFWC_Cost)
	SetTabOrder("mFWC_Cost",		 	mFWC_Cost,				mFWC_HandicapBase)
	SetTabOrder("mFWC_HandicapBase", 	mFWC_HandicapBase,		mFWC_HandicapPercent)
	SetTabOrder("mFWC_HandicapPercent",	mFWC_HandicapPercent, 	mFWC_BonusPins)
	SetTabOrder("mFWC_BonusPins",	 	mFWC_BonusPins,		 	mFWC_FWName)
End Sub

All the Field Events are set to mFWC_EditText

and I process in the following subs

B4X:
Sub mFWC_EditText_EnterPressed
	Dim ETInfo 			As sETInfo
    Dim currentView		As View
	Dim nextField 		As EditText
	Dim currentField	As EditText
	Dim Value			As Int
    
    currentField = Sender
	
	ETInfo.Initialize
	ETInfo		 = currentField.Tag
	
	currentField = ETInfo.Field
    nextField    = ETInfo.NextTab
	
	
Log("1)FWData:" &gFWCreateData.FrameworkName &"  Field:" &mFWC_FWName.Text)
   
   	Select ETInfo.FieldName
	  Case "mFWC_StartsAtGame"
Log("2)FWData:" &gFWCreateData.FrameworkName &"  Field:" &mFWC_FWName.Text)
	  
	  		Value = cGenFuncs.StrToInt(currentField.Text)
			
			If Value < 0 OR Value > 4 Then
			   cGenFuncs.MessageBox("Range is 1 to 4", "Invalid Starting Game")
			   currentField.RequestFocus
			   Return
			End If
			
	  Case "mFWC_NumberOfGames"
Log("3)FWData:" &gFWCreateData.FrameworkName &"  Field:" &mFWC_FWName.Text)
	  
	  		Value = cGenFuncs.StrToInt(currentField.Text)
			
			If Value < 0 OR Value > 4 Then
			   cGenFuncs.MessageBox("Range is 1 to 4", "Invalid Starting Game")
			   currentField.RequestFocus
			   Return
			Else
			   Dim StartGame As Int = cGenFuncs.StrToInt(mFWC_StartsAtGame.Text)
			   
			   If  StartGame + Value > 4 Then
				   cGenFuncs.MessageBox("Starting game plus number of games MUST be less than 4", "Invalid Number of Games")
				   currentField.RequestFocus
				   Return			   
			   End If
			End If
			
	  Case "mFWC_Cost"
Log("4)FWData:" &gFWCreateData.FrameworkName &"  Field:" &mFWC_FWName.Text)
	  
	  		currentField.Text = cGenFuncs.MoneyToStr(cGenFuncs.StrToMoney(currentField.Text))
			
	  Case "mFWC_HandicapBase"
Log("5)FWData:" &gFWCreateData.FrameworkName &"  Field:" &mFWC_FWName.Text)
	  
	  		Value = cGenFuncs.StrToInt(currentField.Text)
			
			If Value < 0 OR Value > 300 Then
			   cGenFuncs.MessageBox("Range is 0 to 300", "Invalid Handicap Base")
			   currentField.RequestFocus
			   Return
			End If
			
	  Case "mFWC_HandicapPercent"
Log("6)FWData:" &gFWCreateData.FrameworkName &"  Field:" &mFWC_FWName.Text)
	  
	  		Value = cGenFuncs.StrToInt(currentField.Text)
			
			If Value < 0 OR Value > 100 Then
			   cGenFuncs.MessageBox("Range is 1 to 100", "Invalid Handicap Percentage")
			   currentField.RequestFocus
			   Return
			End If
			
	  Case "mFWC_BonusPins"
Log("7)FWData:" &gFWCreateData.FrameworkName &"  Field:" &mFWC_FWName.Text)
	  
	  		Value = cGenFuncs.StrToInt(currentField.Text)
			
			If Value > 10 Then
			   cGenFuncs.MessageBox("Range is 0 to 10", "Invalid Bonus Pins")
			   currentField.RequestFocus
			   Return
			End If					
			
	  Case Else
Log("7a)FWData:" &gFWCreateData.FrameworkName &"  Field:" &mFWC_FWName.Text)
	End	Select

Log("8)FWData:" &gFWCreateData.FrameworkName &"  Field:" &mFWC_FWName.Text)
	  
	  
    Do While nextField.Enabled = False
Log("9)FWData:" &gFWCreateData.FrameworkName &"  Field:" &mFWC_FWName.Text)
	
	   ETInfo    = nextField.Tag
   	   nextField = ETInfo.NextTab
    Loop

Log("A)FWData:" &gFWCreateData.FrameworkName &"  Field:" &mFWC_FWName.Text)
   
    nextField.RequestFocus
End Sub

Sub mFWC_EditText_TextChanged (Old As String, New As String)	
	Log("Old:" &Old &"  New:" &New)
End Sub

Sorry for all the Log messages, just trying to see if my case statement was causing this. But it doesn't appear so.

Thanks for any help

BobVal
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I put the follow code in EnterPressed and TextChanged

In EnterPressed:
B4X:
	Log("-----------------------------------------------------")
	Log("EnterPressed")
	Log("-----------------------------------------------------")	
	Log("         mFWC_FWName:" &mFWC_FWName.Text)
	Log("   mFWC_StartsAtGame:" &mFWC_StartsAtGame.Text)
	Log("  mFWC_NumberOfGames:" &mFWC_NumberOfGames.Text)
	Log("           mFWC_Cost:" &mFWC_Cost.Text)
	Log("   mFWC_HandicapBase:" &mFWC_HandicapBase.Text)
	Log("mFWC_HandicapPercent:" &mFWC_HandicapPercent.Text)
	Log("      mFWC_BonusPins:" &mFWC_BonusPins.Text)
	Log("-----------------------------------------------------")

In TextChanged
B4X:
	Log("Old:" &Old &"  New:" &New)


And these are the log Messages printed

Old:210 New:21
Old:21 New:2
Old:2 New:
Old: New:m
Old:m New:mo
Old:mo New:mon
Old:mon New:mond
Old:mond New:monda
Old:monda New:monday
Old:monday New:Monday
Old:Monday New:Monday
-----------------------------------------------------
EnterPressed
-----------------------------------------------------
mFWC_FWName:Monday
mFWC_StartsAtGame:3
mFWC_NumberOfGames:1
mFWC_Cost:3.00
mFWC_HandicapBase:210
mFWC_HandicapPercent:100
mFWC_BonusPins:8
-----------------------------------------------------
Old:3 New:
Old: New:1
Old:1 New:
Old: New:1
-----------------------------------------------------
EnterPressed
-----------------------------------------------------
mFWC_FWName:1
mFWC_StartsAtGame:1
mFWC_NumberOfGames:1
mFWC_Cost:3.00
mFWC_HandicapBase:210
mFWC_HandicapPercent:100
mFWC_BonusPins:8
-----------------------------------------------------
Old:1 New:
Old: New:2
-----------------------------------------------------
EnterPressed
-----------------------------------------------------
mFWC_FWName:2
mFWC_StartsAtGame:1
mFWC_NumberOfGames:2
mFWC_Cost:3.00
mFWC_HandicapBase:210
mFWC_HandicapPercent:100
mFWC_BonusPins:8
-----------------------------------------------------

Everytime I leave one of the fields by Done the first field is getting it's value. Is this a byproduct of using the Tag for tab order?
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Well I figured it out.

I had a field called gLastFocus dimmed in my Globals as
B4X:
Dim gLastFocus					As EditText

in the sub routine
B4X:
Sub mFWC_EditText_FocusChanged(HasFocus As Boolean)
	If HasFocus Then gLastFocus = Sender	
End Sub

In my create routine I had
B4X:
	gLastFocus.Initialize("EditText")	
	gLastFocus = mFWC_FWName

What I was trying to do was to remember who had the last focus.

But I guess doing gLastFocus = sender ' actually set the made mFWC_FWName have the data from sender?

I am a little confused why sender did not just set the gLastFocus to the field that had the last focus.

Would you please explain this Erel

Thanks - any case problem fixed
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Nothing. I thought that gLastFocus (being a dim variable) needed to be initialized and used EditText to say what type of field it was
 
Upvote 0

cbal03

Member
Licensed User
Longtime User
if you use the designer to build your forms then you can arrange your views to receive focus in the hierchy pane. drag them in the order youd like to 'tab' through. The first one receives focus when your layout is displayed.
Cheers!
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
if you use the designer to build your forms then you can arrange your views to receive focus in the hierchy pane. drag them in the order youd like to 'tab' through. The first one receives focus when your layout is displayed.
Cheers!
Just what I was looking for. What is the hierchy pane?
 
Upvote 0
Top