Getting the Sender from a EditPressed event

SeaCay

Member
Licensed User
Longtime User
Hello All

I am using multiple EditText Boxes that all fire the same EnterPressed event. I need to identify which specific EditText box fired the event. The code I am using is:

B4X:
Sub Edit_EnterPressed
  Dim edt As EditText
  Dim edtTag As Int
   
   
      If (Sender Is EditText) Then
         edt = Sender
         edtTag = getViewId(edt.Tag)
The line "If (Sender is EditText) Then" always returns false. When I test sender with

B4X:
Dim aView as View
  aView = Sender

I get a message that Sender is a null pointer.

How can I correct this and determine the requesting EditText?

regards and thanks

SeaCay
 

SeaCay

Member
Licensed User
Longtime User
Hello Erel,

Thanks for your prompt reply. Your assurance that sender should have an initialized value, suggests that I should re-look at what I'm doing.

In the project concerned, all my Views: Labels, EditTexts, Spinners, CheckBoxes, etc are dynamically created at runtime, initialized and usable on the UI (tested and proven many times). All views are based on the contents of an XML file. All views are members of their "control type" array. Each view has a complex value for the tag. The entire view collection is spread out over 6 panels (also dynamically created).

The project is extremely complex in nature. I do not feel that creating a zip would help in this particular instance as "getting to grips" with the project would consume more time that working out why "sender" seems to be a null pointer.

However I will revert to small-time testing on a new dummy project. If I get the same error, I'll upload that project.

Again, my thanks for your support and re-assurance.

regards

SeaCay
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
What do you get if you just do

Log(Sender)



-------------------
Sent via Tapatalk
 
Upvote 0

SeaCay

Member
Licensed User
Longtime User
Hello Steve05

I have put a few log statements in and around the entry point of my EditText "EnterPressed" Sub. The output from logging reads

Entering Edit_EnterPressed
Logging Sender
android,widget.EditText@419e18e8
Sender Logged

regards

SeaCay
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
That's as expected, how about if you put:

B4X:
Log(Sender Is EditText)

directly after if.
 
Upvote 0

SeaCay

Member
Licensed User
Longtime User
Hello Stevel05

This is getting weirder by the moment. Here's my code:

B4X:
Sub Edit_EnterPressed
   Dim edt As EditText
   Dim edtTag As Int
   Dim aView As View
   
      Log("Entering Edit_EnterPressed")
      Log("Logging Sender")
      Log(Sender)
      Log("Sender Logged")
      Log(Sender Is EditText)
      Log(FBEdits)
      
      aView = Sender
   
      If (Sender Is EditText) Then
         Log("Sender is being processed as EditText")
         edt = aView
         edtTag = getViewId(edt.Tag)
      
      Else
         Log("Sender is not being processed as EditText")
         Log(Sender)
      End If
End Sub

This is the output from the log statements

Entering Edit_EnterPressed
Logging Sender
android.widget.EditText@4197e8c0
Sender Logged
true
[Lanywheresoftware.b4a.objects.EditTextWrapper;@418e9e68
Sender is not being processed as EditText
null

The fifth entry says "true". And this is what I would expect it to say that Sender is an EditText.

However when my code "If (Sender Is EditText) Then" is executed it is return as false and my conditional block is ignored completely. When this "If" statement is executed, it has changed from EditText to Null.

I don't know why this should happen. Grateful for any thoughts.

regards

SeaCay
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Hmm, just pasted you code into a minimal project, 1 EditText in designer and EnterPresed callback, and it works as expected. I had to remove the Log(FBEdits) line.

What happens if you remove the two lines:

B4X:
Log(FBEdits)
aView = Sender

And assign edt = Sender after the
B4X:
If (Sender Is editText) Then
test?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Have you checked the unfiltered logs for unexpected error messages?
 
Upvote 0

SeaCay

Member
Licensed User
Longtime User
Hello Stevel05,

Thank you for your continued interest in this problem.

The FBEdits is the array of EditTexts that are created at runtime and I logged them as an integrity check. Now commented out.

My code now reads

B4X:
Sub Edt_EnterPressed
   Dim edt As EditText
   Dim edtTag As Int
   Dim aView As View
   
      Log("Entering Edit_EnterPressed")
      Log("Logging Sender")
      Log(Sender)
      Log("Sender Logged")
      Log(Sender Is EditText)
'      Log(FBEdits)  commented out
      
      If (Sender Is EditText) Then
         Log("Sender is being processed as EditText")
         aView = Sender  ' Moved from before the if
         edt = aView
         edtTag = getViewId(edt.Tag)
      
      Else
         Log("Sender is not being processed as EditText")
         Log(Sender)
      End If
End Sub

The log returns

Entering Edit_EnterPressed
Logging Sender
android.widget.EditText@419a5c50
Sender Logged
true
Sender is not being processed as EditText
null

Sadly no change to the outcome.

As earlier mentioned, the EditTexts are created at run time. I do not destroy these views in code, I let the garbage collector do the cleanup. Other details, this app is single threaded and the testing (and target platform) environment is a Samsung Galaxy Note GT-N7000 running Ice-Cream Sandwich 4.0.3.

I believe that the sender is must have been initialized, otherwise how would this EnterPressed event get fired when the Done/Next keyboard button is tapped.

Next step remove the Log Filter. This may take some time.

regards and many thanks

SeaCay
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You have

B4X:
Dim edt As EditText
as a local variable in the Pressed sub, is that the same name as the global variable edittext that is calling the sub?
 
Upvote 0

SeaCay

Member
Licensed User
Longtime User
Hello All,

I have good news and for me, bad news. I think I have found the cause of the problem and it would appear to be "right out of left field".

I do not use a mouse/touchpad for development. I use a Wacom tablet with a pen/stylus.

When testing I use the Wacom tablet extensively. I don't need to keep picking up and putting down a mouse but can constantly hold the pen in my hand and work the keyboard without issue.

On reviewing the unfiltered log, I noticed a few "Wacom" calls. This led to me disconnecting the tablet and using the touch pad.

Bingo - the log now reads

Entering Edit_EnterPressed
Logging Sender
android.widget.EditText@419aeda0
Sender Logged
true
Sender is being processed as EditText

So that's the good news. And my bad news is I don't know why this should be true. Any hardware Guru's like to have a stab at this?

regards

SeaCay

PS Stevel05: Thanks so much for your encouragement and interest. You were truly observant about the "Dim Edt" perspective. In between our message exchanges, it crossed my mind that "Edit"_ might be too generic or that "Edit" in general was too vague or conflicting with some other reference. So I changed my initialization to "Edt" from "Edit". This change made no difference.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
At least there's an answer, if not yet a reason.

Just curious, what environment are you using to test? SDK emulator, Bluestacks, VM?
 
Upvote 0

SeaCay

Member
Licensed User
Longtime User
Hello Stevel05

Nothing so glorious as emulation. I'm testing straight to the Android Smartphone hardware (Samsung Galaxy Note Gt-N7000 [XXLPT] 800 x 1280).

And that makes even more curious as to why the Wacom hardware would be interfering with the Android. At least I have a cause and effect result but it is nonsensical.

regards

SeaCay
 
Upvote 0
Top