Beware of Froyo Not B4A

Mahares

Expert
Licensed User
Longtime User
I have a few edittext views that were created on the designer where I set their Enable property to False. Strangely enough, on a device with Froyo 2.2 as the OS, I can enter data in those boxes that are supposedly disabled. I tried the same application on a newer OS and I could not enter data, which is what supposed to happen. If someone has a workaround Froyo, where I want to be prevented from entering data in a disabled edittext view, I appreciate it.
Thank you.
 

Mahares

Expert
Licensed User
Longtime User
Thanks NJ. It took me a few hours as usual to figure that one out. Before looking for a fix for it in the forum, evidently, I was suspecting my code. So, I spent a good bit of time trying to debug it, to no avail.
At any rate, can you explain how to do the following: When you give someone a link, you have the word 'THIS'. How are you replacing the link with 'THIS'. Is that a feature in the forum question form.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Thanks NJ and TDS for your prompt and accurate responses. Do I feel lucky today. Two heavy hitters answered my post.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Still having trouble with the workaround. but the error is: The application XYZ stopped unexpectedly. Try again. Force close. Can you see the problem with the code below?:
B4X:
Sub Froyo_TextChanged (Old As String, New As String)
  'Froyo is event name. Workaround. In reference to a bug in OS Froyo where disabled views allow to type on. 
   Dim Send As EditText
   Send=Sender
   If Send.Enabled=False Then
      Send.Text=Old
   End If   
End Sub
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Still having trouble with the workaround. but the error is: The application XYZ stopped unexpectedly. Try again. Force close. Can you see the problem with the code below?:
B4X:
Sub Froyo_TextChanged (Old As String, New As String)
  'Froyo is event name. Workaround. In reference to a bug in OS Froyo where disabled views allow to type on. 
   Dim Send As EditText
   Send=Sender
   If Send.Enabled=False Then
      Send.Text=Old
   End If   
End Sub

I think that the problem is that when you tell the txtBox to get its old value, the very same subroutine 'text_changed' is called again, thus leading to an inifinite loop.
Perhaps, you could use the focus_changed event, having a variable let's say 'constantTxt' containing the original txtBox's content, and then checking if hasFocus turns to False and getting your origininal content back.
B4X:
Sub Froyo_FocusChanged (HasFocus As Boolean)
dim txtBox as edittext
txtbox=sender
if txtbox.enabled=false and hasfocus=false then txtbox.text=constantTxt
End Sub
In case you have many disabled textboxes, you could use their tag property and place back their original content by quering it from their tags.
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Still having trouble with the workaround. but the error is: The application XYZ stopped unexpectedly. Try again. Force close. Can you see the problem with the code below?:
B4X:
Sub Froyo_TextChanged (Old As String, New As String)
  'Froyo is event name. Workaround. In reference to a bug in OS Froyo where disabled views allow to type on. 
   Dim Send As EditText
   Send=Sender
   If Send.Enabled=False Then
      Send.Text=Old
   End If   
End Sub

In the TextChanged sub, add a line that checks if Old = New, and if it does return from the sub, this avoids the infinite loop problem.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
As you can see in the code I placed the if old=new line in several placements and none worked. I get the same fatal error: stopped unexpectedly.

B4X:
Sub Froyo_TextChanged (Old As String, New As String)
  'Froyo is event name. Workaround. In reference to a bug in OS Froyo where disabled views allow to type on. 
'      If Old = New Then :Return  :End If
    Dim Send As EditText
    Send=Sender
    If Send.Enabled=False Then
        Send.Text=Old
'            If Old = New Then :Return  :End If
    End If  
'      If Old = New Then :Return  :End If
End Sub

Using the hasfocus method may work as mc73 suggested. The only problem is: I would have to save all disabled edittext views original text to their tags. Then, at the end, when the record is saved, I will have to reset all tags back to blank. Otherwise, they will inherit the previous record tags. There are too many of them.
Thanks
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Sorry, my mistake. I now remember how I worked around this. What I did is used the visible property as a flag:

B4X:
Sub Froyo_TextChanged (Old As String, New As String) 
    Dim Send As EditText    
    Send=Sender
    If Send.Enabled = False Then    
        If Send.Visible Then
            Send.Visible = False
            Send.Text = Old
        Else
            Send.Visible = True
        End If
    End If
End Sub

You could equally use the tag property to store this flag if using Visible creates problems.
 
Last edited:
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Or you could dim a flag outside of the routine, as for e.g.
B4X:
    Dim txtSubRunning As Boolean
and then write something like this:
B4X:
If txtSubRunning=True Then
txtSubRunning=False
Return
Else
txtSubRunning=True
If old<>new Then
Dim txt As EditText 
txt=Sender
txt.Text=old
End If
End If
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Thank you kickaha and mc73. I just experimented with Kickaha's code snippet. I will do the same with mc73 and report back to you. Here is the verdict on Kickaha's: It works well, except that all disabled editetxt views get displayed at the same time. In my application, depending of the task selected a certain number of views display out of many because they are relevant to the task selected. But, here all views show up. Although they do not interfere with the final outcome, esthetically, they make the panel crowded with disabled boxes that need to be hidden.
Here is the culprit line:
B4X:
Send.Visible = True
Thank you
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Thank you kickaha and mc73. I just experimented with Kickaha's code snippet. I will do the same with mc73 and report back to you. Here is the verdict on Kickaha's: It works well, except that all disabled editetxt views get displayed at the same time. In my application, depending of the task selected a certain number of views display out of many because they are relevant to the task selected. But, here all views show up. Although they do not interfere with the final outcome, esthetically, they make the panel crowded with disabled boxes that need to be hidden.
Here is the culprit line:
B4X:
Send.Visible = True
Thank you

In that case using an external flag is more appropriate, add the following to the Globals Sub
B4X:
Dim EditChanged As Boolean
EditChanged = True

Then the Changed sub becomes
B4X:
Sub Froyo_TextChanged (Old As String, New As String)
    Dim Send As EditText
    Send=Sender
    If Send.Enabled = False Then
        If EditChanged Then
            EditChanged  = False
            Send.Text = Old
        Else
            EditChanged  = True
        End If
    End If
End Sub
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
@Kickaha: The problem is getting deeper now. I get an error number format exception.
Here is my scenario:
1. Each disabled edittext view is a previous reading. It is subtracted from the current reading which is an enabled edittext view. In my code, when the previous reading is blank, I force it to be equal to the current so I do not subtract a blank from a number to avoid the error.
2. By virtue of us now telling it Send.Text = Old, we are forcing it back to its original blank value. Therefore, when subtracting it from the current reading which is numeric, I get the error mentioned above.
Thank you for your perseverance
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
What you need to do is before you set the disabled EditText to a previous reading is to set EditChanged to False so that the change will be accepted as Send.Text = Old will not be processed but the flag will be reset ready for the next operation.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
What you need to do is before you set the disabled EditText to a previous reading is to set EditChanged to False

Soorry Kickaha. This is not going to work. The previous reading is extracted from a SQLite table. Usually the previous reading is a number. But when it is blank, I override it by setting it equal to the current reading entered in the enable text box. I tried to set the flag to false before extracting the previous readings, but it started showing the previous readings boxes that are disabled that were supposed to be hidden. In other words, it unhid all the disabled text boxes, which is not appropriate. It seems that the only solution is to tell the user not to click on a disabled box for the program to work properly, until they upgrade to a newer OS version. Thank you very much for your efforts.
 
Upvote 0

bluejay

Active Member
Licensed User
Longtime User
Another alternative is to place a transparent button under the EditText and use:

btn.BringToFront to disable the edit text and
EditText.BringtoFront to enable it.

I sometime do this to programatically turn EditText boxes into temporary buttons and to prevent editing of the EditText box.

BlueJay
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
There are too many disabled text boxes to try to create equivalent number of buttons underneath. Plus I do not want to enable any of the DISabled buttons. Each gets its value from the previous record value which is sometimes not blank, so its value must be visible to the user whenever he or she is entering a value in the current editbox. The problem would not have been complex if I did not have to include these DISABLED text boxes in mathematical calculations. Perhaps Erel, NJDude or Klaus can tackle this challenge. If not, the user must be warned not to touch the disable text boxes.
I tried mc73 and Kickaha's methods also with no success.
Thank you
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
I don't know how you have your EditBoxes, how many, etc, but you could place dynamically a transparent panel on top of the EditBoxes you want to disable, take a look at the attached project it might give you an idea.
 

Attachments

  • EditTextSample.zip
    7.2 KB · Views: 175
Upvote 0
Top