edittext problems

Smee

Well-Known Member
Licensed User
Longtime User
I am having an inordinate amount of trouble trying to get the value of a text box

I have added it in the designer

when i log its use;
B4X:
Dim etOptions As EditText
...
...


Sub etOptions_EnterPressed
   Log(etOptions.Text)
End Sub

If i dont initialise it i get an error.

if i do init
etOptions.Initialize("etOptions")

the text is empty

if i pause the code i get the following
etOptions = (EditText):Layout not available, Text=

Any ideas?
 

klaus

Expert
Licensed User
Longtime User
Are you shure that the name etOptions is exactly the same as the Name in the Designer ?
Are you shure that the EventName you entered in the Designer is also etOptions ?
Where is the Dim etOptions As EditText ?

It would be easier to find the problem if you posted the whole project as a zip file (IDE menu File / Export as Zip).

Best regards.
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
Activity.LoadLayout("numPanelLayout")

I can interact with the message box i.e enter multi lines of text

I did not initialize until i got the error saying it needed to be initialised

Klaus

I copied and passted the name to make sure no typos

it is dim in Globals not Process_Globals
and it is in an activity module

I might try a small program just using the layout and see if it works

are there any posts regarding parsing the multiline textbox? I will need to get a listing of each line of text eventually

Thanks for the help
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
If etOptions is on the layout you are loading, you need to remove the line
B4X:
Dim etOptions As EditText
completely, as the layout loading takes care of the "Dim"ing, and by having that line you are creating another EditText with the same name.

Edit to add: Also you do not need to initialize it.
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
So how do i access the text? if i remove the dim then i will get an error with

txt= etOptions.text wont I?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You do need the Dim statement in the Sub Globals , the designer will put that there when you use generate members (unless it's already there).
 
Last edited:
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
i tried to run with the init statement but i get an error message saying it has to be initialised

Time for bed i think and try again tomorrow:BangHead:
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
Ok i have uploaded a sample. Can anyone see what is wrong?

Thanks

joe
 

Attachments

  • EditTextTest.zip
    6.3 KB · Views: 188
Upvote 0

devlei

Active Member
Licensed User
Longtime User
Being a newbie myself, I'm not sure, but it would seem like you have given your EditText view different values for 'Name' and 'EventName'.

When I add a view in Designer and give it a 'Name', then Tab off the 'Name' it automatically gives the 'EventName' the same name. This makes it simple to know what belongs to what in the Module.

I'm not sure how you add your Dim statements and Event statements, but I always use the Tools ... Generate Members to do it, then I know there are no typo's etc. Also then you never have to worry about initializing those objects.

Hope that helps.

PS I first struggled to even find any of your views, because the panel was way off the screen on my emulator. Is everything meant to be so far off to the right?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Yes, you have called the edittext edittext1 in the designer and dimmed it as etoptions, as devlei suggests, these names should be the same. Same with the buttons.

Dim EditText1 As EditText instead of dim etOptions as EditText.

You need one Dim statement for each object that you want to access from the designer.
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
Yes thank you,

I was just playing around with that small bit of code and realised what i had done.

Many thanks for your input all

Joe
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
PS I first struggled to even find any of your views, because the panel was way off the screen on my emulator. Is everything meant to be so far off to the right?

Yes its on a tablet in portrait mode.

Thanks for the info

Joe
 
Upvote 0
Top