Android Question Clear edit field immediatly

andredamen

Active Member
Licensed User
Longtime User
I want to clear an editfield. I program it with edtfield.clear. When I log the editfield I see it is empty but on the screen I stil see the old text. Later in the app I fill the editfield. It clears and fill with new text.
What I want: I want the clear the edit field and want to see a clear editfield immediatly on the screen. How can I do this?
 

Addo

Well-Known Member
Licensed User
Longtime User
You are a lucky one Sagenut.

B4X:
private Sub LeegEditVeld
    edtVeld.Text=""
   
    edtVeld.TextField.Text = ""

    edtVeld.Text = "Indeling toss-wedstrijden "& Main.WelkeTossDatum & CRLF & CRLF
   
End Sub

Doesn't work with me.
Are you sure that this sub executed ? Upload sample project that we can run and test.
 
Upvote 0

andredamen

Active Member
Licensed User
Longtime User
Are you sure that this sub executed ? Upload sample project that we can run and test.

B4X:
Private Sub btnOpnieuwTossen_Click
	TossenIsGelukt=False

	LeegEditVeld
  
	For ot = 1 To 40
		ToastMessageShow("Toss ronde nummer "& ot,False)
		GaOpnieuwTossen(ot)
	   If TossenIsGelukt Then Exit
	Next
	
End Sub

When I click on the button btnOpnieuwTossen I am sure that this sub is executed.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Your code looks a bit tricky to me.
Every Sub call another Sub, that call another Sub.
Maybe some event just does not have time to happen/finish.
Just guessing.
It looks like there is another call
B4X:
WieNietIngetost
and we don't know what is it.
 
Upvote 0

andredamen

Active Member
Licensed User
Longtime User
Unless after you cleared the Text and you are inserting new Text again.

It doesn't clear the text immediately . When I put text in this field after doing some subs the field is cleared and filled with the new text. But ..... I want to see first a compleet empty text field so the user can see that the app is doing his thing again.
 
Upvote 0

Addo

Well-Known Member
Licensed User
Longtime User
It doesn't clear the text immediately . When I put text in this field after doing some subs the field is cleared and filled with the new text. But ..... I want to see first a compleet empty text field so the user can see that the app is doing his thing again.
Sounds more that it did clear the text and placed a new one immediately which means thats how it should be. And i don't know if i understand correctly you want to clear the text first then let the user see that your text field has been cleared then adding a new one correct?
 
Upvote 0

andredamen

Active Member
Licensed User
Longtime User
Your code looks a bit tricky to me.
Every Sub call another Sub, that call another Sub.
Maybe some event just does not have time to happen/finish.
Just guessing.
It looks like there is another call
B4X:
WieNietIngetost
and we don't know what is it.

Sagenut,

I also dit think that it has no time to execute. But when I push the button btnOpnieuwtossen this button gets another color (Red). When the app runs all the subs needed for the toss and fill the database this button still has the red color. When that is finished the color of that button becomes Grey. These routines needs about 5 to 8 seconds. I think enough time to les me see a clear edith field.

Is a big project with a lot of code. Come back to this later when I've made a small app as an example.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Here
B4X:
For ot = 1 To 40
   ToastMessageShow("Toss ronde nummer "& ot,False)
   GaOpnieuwTossen(ot)
   If TossenIsGelukt Then Exit
Next
you call 40 times without stop the sub
B4X:
GaOpnieuwTossen
In this sub you make it clear
B4X:
edtVeld.Text=""
but immediately call
B4X:
VulEditVeld
that contain
B4X:
edtVeld.Text = "Indeling toss-wedstrijden "& Main.WelkeTossDatum & CRLF & CRLF
I think that is just a matter of understanding where you need to pause something that you want to see happening. :)
Hoping that I followed the flow correctly.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Just as a test, try this (do not cancel your code if you want to roll back)
B4X:
Private Sub btnOpnieuwTossen_Click
    TossenIsGelukt=False
    edtVeld.Text=""

    For ot = 1 To 40
        ToastMessageShow("Toss ronde nummer "& ot,False)
        Wait For (GaOpnieuwTossen(ot)) complete (Finished As Boolean)
        Sleep(1000)
        If TossenIsGelukt Then Exit
    Next
   
End Sub


Private Sub GaOpnieuwTossen(hoevaak As Int) As ResumableSub
    Dim Doorgaan As Boolean

    btnOpnieuwTossen.Enabled=False
    MetSterkte= chkSterkte.Checked

    SpelersIngepland = 0
    edtVeld.Text=""
    Sleep(1000)
    VoorkeurSpelerNaam =""
    VoorkeurSpelerID = 0
    VoorkeurSpelerSterkte=0
   
    btnVeld1.Enabled=False
    btnVeld2.Enabled=False
    btnVeld3.Enabled=False
    btnVeld4.Enabled=False
    btnVeld5.Enabled=False
   
    ZieVeld = 1

    txt="DELETE FROM '"& Main.DBTableName1 & "' where datum =  '"&  Main.WelkeTossDatum & "' "   ' alle wedstrijden deze datum verwijderd
    Main.SQL1.ExecNonQuery(txt)

    'from here it fills a database afther making a toss


    Wait For (VulEditVeld) complete (Finished As Object)
    Return True
'    VulEditVeld     ' this will fill the edit field with new data

End Sub

Private Sub VulEditVeld As ResumableSub
    Dim Oudetijd As String
    Dim Dummy As Int
   
   
    WieNietIngetost
    If TossenIsGelukt=False Then Return Null

    edtVeld.Text = "Indeling toss-wedstrijden "& Main.WelkeTossDatum & CRLF & CRLF
    Return Null

    'from here it will fill the field further

End Sub
For me it's a jump in the darkness as I don't know what the app should do.
 
Last edited:
Upvote 0

andredamen

Active Member
Licensed User
Longtime User
Here
B4X:
For ot = 1 To 40
   ToastMessageShow("Toss ronde nummer "& ot,False)
   GaOpnieuwTossen(ot)
   If TossenIsGelukt Then Exit
Next
you call 40 times without stop the sub
B4X:
GaOpnieuwTossen
In this sub you make it clear
B4X:
edtVeld.Text=""
but immediately call
B4X:
VulEditVeld
that contain
B4X:
edtVeld.Text = "Indeling toss-wedstrijden "& Main.WelkeTossDatum & CRLF & CRLF
I think that is just a matter of understanding where you need to pause something that you want to see happening. :)
Hoping that I followed the flow correctly.

I solved it as follows: one has to press the "bthOpnieuwTossen" button 2 times. After the first press, the text field is cleared. After the 2nd time, the toss starts again (sometimes 40x). Now the field is cleared. Between the 2 times pushing there is enough pause to clear the field.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I solved it as follows: one has to press the "bthOpnieuwTossen" button 2 times. After the first press, the text field is cleared. After the 2nd time, the toss starts again (sometimes 40x). Now the field is cleared. Between the 2 times pushing there is enough pause to clear the field.
So, maybe you just was needing this
B4X:
Private Sub btnOpnieuwTossen_Click
    TossenIsGelukt=False
    edtVeld.Text=""
   
    Sleep(2000) 'Give 2 seconds to see the empty field
   
    For ot = 1 To 40
        ToastMessageShow("Toss ronde nummer "& ot,False)
        Wait For (GaOpnieuwTossen(ot)) complete (Finished As Boolean)
        If TossenIsGelukt Then Exit
    Next
   
End Sub
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
This thread could be 2 post long if there would be an example project that recreate the issue. The snippet above doesn't make any sense. You clear the text and then set a new text in the same event. There is no reason in this scenario to see a cleared textfield. As @Sagenut said the sleep() function will solve the issue.
 
Upvote 0
Top