Android Question Where is TextView in B4A?


I'm trying to get a view only scroll-able text box in my application.

I consulted ChatGPT and had it write a couple of "Subs" for this, I'll include them here.
When the code is dropped into my B4A pages application the "TextView" type is marked in red since
the IDE doesn't know that type. I can't find a library for it, some say it's built in? My suspect is that
it's in the Android SDK and need some sort of link up to the Android SDK some how, please help?

I included the comments ChatGPT gave along with the code it generated for me. It seems to be mixed
up somehow on TextView as I interrogated where and how it got this type to use and it simply states
that is is a built in with the couple of required libraries for all B4A applications, right, well, it needs to
learn a bit more. I did say this should work in V12.20 of B4A. I could not provide how to like the item
to any other deep down Android SDK libraries or Java as such though, so I hit it's limit of knowledge.

ChatGPT code stubs.:
'In this example, we define a separate CreateTextViewWithScrolling sub that
'takes a text parameter and returns a TextView. This sub creates the ScrollView
'and TextView with the given text, and adds the TextView to the ScrollView's panel.
'The Activity_Create sub then calls this sub to create the TextView and add it to
'activity's view hierarchy. This way, you can create a TextView with scrolling
'and no edit anytime by calling the CreateTextViewWithScrolling sub and passing
'it the desired text as a parameter.

'In this updated code, we declare the variables For the ScrollView And
'TextView at the top of the CreateTextViewWithScrolling sub, and then
'create And Initialize them later in the code. This makes the code more
'readable And easier To modify.

Sub Activity_Create(FirstTime As Boolean)
    ' Call CreateTextViewWithScrolling sub to create the TextView
    Dim TextView1 As TextView = CreateTextViewWithScrolling("This is a long text that requires scrolling to see all of it.")
    Activity.AddView(TextView1, 0, 0, 100%x, 100%y)
End Sub

Sub CreateTextViewWithScrolling(text As String) As TextView
    ' Declare variables
    Dim ScrollView1 As ScrollView
    Dim TextView1 As TextView

    ' Create a ScrollView to contain the TextView
    ScrollView1.Initialize(0, 0, 100%x, 100%y)

    ' Create a TextView with scrolling enabled and editing disabled
    TextView1.Text = text
    TextView1.Color = Colors.White
    TextView1.Gravity = Gravity.LEFT
    TextView1.TextSize = 16
    TextView1.ScrollingEnabled = True
    TextView1.Enabled = False ' Disable editing

    ' Add the TextView to the ScrollView's panel
    ScrollView1.Panel.AddView(TextView1, 0, 0, 100%x, 100%y)

    ' Return the created TextView
    Return TextView1
End Sub

" TextView1.ScrollingEnabled = True " appears ScrollingEnabled isn't available either?
I also had it write a version using a "Label" and also has the same missing item in the "Label" version
which I'll include here too for those to critique and maybe correct:

ChatGPT code stubs, text box, scrollable, no edit. No comple?:
Sub Page_Create(Title As String)
    ' Create a ScrollView to contain the Label
    Dim ScrollView1 As ScrollView
    Page.RootPanel.AddView(ScrollView1, 0, 0, 100%x, 100%y)

    ' Call CreateLabelWithScrolling sub to create the Label
    Dim lbl As Label
    lbl = CreateLabelWithScrolling("This is a long text that requires scrolling to see all of it.")

    ' Add the Label to the ScrollView's panel
    ScrollView1.Panel.AddView(lbl, 0, 0, 100%x, 100%y)
End Sub

Sub CreateLabelWithScrolling(text As String) As Label
    ' Declare variables
    Dim ScrollView1 As ScrollView
    Dim Label1 As Label

    ' Create a ScrollView to contain the Label
    ScrollView1.Initialize(0, 0, 100%x, 100%y)

    ' Create a Label with scrolling enabled and text wrapping
    Label1.Text = text
    Label1.Color = Colors.White
    Label1.Gravity = Gravity.LEFT
    Label1.TextSize = 16
    Label1.SingleLine = False
    Label1.ScrollingEnabled = True

    ' Add the Label to the ScrollView's panel
    ScrollView1.Panel.AddView(Label1, 0, 0, 100%x, 100%y)

    ' Return the created Label
    Return Label1
End Sub

I'm still a NOOB with B4A but well versed in C and firmware, etc... What I find missing is a way
to have knowledge of libraries as stand along documents pdf's on the function calls with in and
arguments and returns. Usually can find an answer in the forums with a good amount of time
though. Did I miss some document or another which would have helped with this TextView
issue and what the "Libraries" selector panel libraries have in them which I might need?

ChatGPT is free to use, but I'm happy to use it to get code laid out and then hammer it to what
I need. But with it using things not in the grat B4X booklets pdf's is a bit tiring, any help?

Thanks in advance!


Licensed User
Longtime User
I find it worrying that people seem to think that ChatGPT is accurate and then question the target rather than questioning the ChatGPT output. ChatGPT makes thing up and lies for God's sake, don't rely on it.
Upvote 0


Active Member
Licensed User
A beginning B4X programmer should start reading the documentation.
Then write simple applications him/her self and test them.
Do the work and you will get expertise!
ChatGPT will not reveal its sources so you can't check where the misinformation comes from.
Upvote 0


Licensed User
Longtime User
@anasazi don't be disheartened. I understand why you used ChatGPT to make an application based on B4X. And also know why it gave vague codes.

First and foremost keep in mind ChatGPT searches the internet for clues like us. Codes of B4X are not thrown all over the internet like Java, VB, C#, Python etc.
B4X is very powerful language in it own way and most codes reside here, in the Forum.

If you want to develop a powerful cross platform application, then start reading the documents, as requested. You do not need to read all, but we suggest start downloading the samples from the Forum and testing them on real mobile, making changes and checking the results. This is the way we old programmers learned at our times Basic, C, dBASE etc.

And the biggest advice is to ask here for any solution you need. You will be surprised how easy it is with B4X.
Upvote 0


Well-Known Member
Licensed User
Longtime User
Why would you use ChatGPT to write code for you? If you're incapable of either writing the code yourself or learning to write it yourself, perhaps you should find another hobby. There are 390,000+ messages in the Android forum on this site - surely you can find at least one that will help you. Using ChatGPT to write your code is like saying "I'm going to become a surgeon, but I can't be bothered studying for however many years it takes so I'll just buy a "Surgery For Dummies" book".

You probably would have gotten there faster by just searching the forums.

- Colin.
Upvote 0


Well-Known Member
Licensed User
Longtime User
Mercy. He is new to B4X and ChatGPT is new fad now.
Let us all welcome him and show the correct path.
I just don't see the point of "developing" apps if you have no skin in the game. If people just start using "tools" like ChatGPT to write code, the app stores are going to be flooded with even more inane & buggy apps & Google & Apple will tighten their app quality policies to the point where even people who are writing their own code will struggle to get apps approved. If somebody is using ChatGPT to write code, they're clearly not interested in the "art" of app development - they're just trying to go straight to the end result without putting in any of the work, ie: they're not interested in the correct path.

Anyway, that's just my opinion & you can agree or not at your pleasure. :)

- Colin.
Upvote 0


Licensed User
Longtime User
Well @anasazi I saw you have been asking here in the Forum and trying to work hard.


Maybe you tried to do shortcut with Chat.
Asking here is still better.
Upvote 0


Well that was fun and thought provoking to be sure. Yes I agree with most all replies. I think ChatGPT is pretty
far off base in my experiments so far with it. I had it write a Flash device mini-filesystem in C which I can do
myself, it came close 1st try but needed hand holding in many parts. I have done other tests with it and found it
came up with a code segment I had published years ago as an Wind River Field Engineer in San Diego. So I see
it pretty much is pattern matching what one asks to what similar patterns it has found on the internet already.
Nothing much new there as we all work(ed) that way. I thought giving it a coding test in a more abstract language
as B4X might trip it up and indeed this is true. I'm not sure where it got the mixture of code objects to toss in
those examples though. It did come up with good C code for TI-RTOS and talking to I2C memory components
as well as the mini-filesystem. I used it as an outline/shell of code for that job and expected it to trip up and I
would need to clean up it's mess. In all, I would say it can get you that, an outline of a task you require and do
it in one quick session. Then the rest is up to you to make work. It fairs well with Arduino simple code as there
is so much it has seen in it's learning phase. I think it put B4X and other IDE's in it's general Android cloud bin
and composes out of that vagueness some sort of reply. I found it learns if you go back and tell it that it made
a mistake and about it's errors, it will rewrite you a new version and go through the hoops again with you. This
is how we all learned some decades ago I would imagine, so I'd leave it at ChatGPT is like a "fresh out" of college
engineer that has concepts but lacks in the details of many things.... will it ever replace us humans? To be seen.. . . .

PS, as side note is how "human" the responses are, ranging from "come under the shade tree and we'll talk as
you ask questions" to "why the hell would you" and "no skin in the game" references. This in and of itself will
be just the sort of "deeper" knowledge OpenAI needs to give that beast a solid back bone. Not so easy to find
on the internet with out someone provoking that back and forth banter of the air breathers from which the real
depth of a future AI system will need to acquire to actually pass the Turing Test, at least as far as when I chat
with it in attempts to confound the "gray matter" it dearly is trying to emulate.
Upvote 0


Licensed User
Longtime User
Agree with you.

I found ChatGPT very very helpful in developing my new version of our application which is on XBase++ into C#, and I do not have any knowledge, forget experience, on C#.

ChatGPT gave me code snippets for nearly all modules I need in C#. Many time wrong codes, but 'regenerate' gave many time the correct or nearly correct code. I take it as C# codes are all over the internet for nearly all possible cases, so it was easy for ChatGPT.

Anyway the point here is that for B4X queries, our Forum with members having deep knowledge of B4X, is the best solution.
Upvote 0