Android Question Changing TabHosts and EditTexts Focus

MCU01

Member
Licensed User
Longtime User
Hi,

I am working on a program where I have 4 Tabs, using TabHost, and in each tab I have like 10 EditText boxes where the user can enter some settings.

The problem that I'm having is that when changing from one tab to another the focus goes to an EditText box where data is already there erasing the entry in that box. I would like the focus to go lets say to an EditText that is disable, so it doesn't show in my screen.

RequestFocus doesn't do anything to solve this problem. Is there any workaround this issue? Any recommendations? This issue is really messing up my program.

Thank you,

Robert
 

MCU01

Member
Licensed User
Longtime User
Thank you Erel for your response. Well, it erases the text because I programmed it that way such that if the user selects an EditText then the text gets erased. But, this is not really the issue. The issue is the focus going to a data box where I don't want it to go.

Hmm, I don't know what CallSubDelay, or CallSubPlus, or the TabStripViewPager is. So, it looks like I have a lot of homework to do. :confused:
 
Upvote 0

MCU01

Member
Licensed User
Longtime User
Hi, I switched to TabStripViewPager and yes it works much better. However, I'm having the same problem as before. When I switch tabs the focus goes to an EditTexts field where I don't want it to go. The RequestFocus command doesn't do anything. It just won't work. I don't know how I can implement the CallSubDelay, or CallSubPlus as you suggested above. Thanks....
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Seems to be that requesting focus for other views that are not editText will not work
There is a workaround for this: just declare another edittext which will not be visible
Each time you change page, request focus for it, so the other EditTExt will lose it

B4X:
Sub Globals

  ' Add these 2 declarations
  Dim fakeEditText as EditText
  Dim mIME as IME   'need to check IME library
End Sub

Sub Activity_Create(FirstTime as Boolean)

   ' Call this before loading your layout
   fakeEditText.initialize("")
   fakeEditText.enabled=False
   Activity.Addview(fakeEditText,0,0,20,20)  'whatever size, since it will not be visible

   ' Now the code as you had it....
   ' ...
End Sub

Sub TabStrip1_PageSelected (Position As Int)    'Change event name as you have defined it

   fakeEditText.requestFocus
   mIME.HideKeyboard
End Sub
 
Upvote 0

MCU01

Member
Licensed User
Longtime User
Jordi, you are good at this!!!! Your code worked well! I'm not sure why, but it worked. I have tried RequestFocus before with another EditText and the code completely ignored my RequestFocus command. The only difference is that before I created the EditText in the Visual Designer and not with the Initialize command. What is the difference?

Also, the mIME doesn't seem to be necessary in my case. Now my code is working fine just with the fakeEditText. Should I include the mIME anyways?
 
Upvote 0

MCU01

Member
Licensed User
Longtime User
Also, I'm getting the following errors with the AddView command. Any idea what it means?

upload_2017-4-10_23-34-3.png
 
Upvote 0
Top