All right, so moving forward here we have our show named Button.
Next thing we want to do is add a text at the bottom, because the idea is to have users when you click
on your name and then something will be shown in order to show something.
We need the actual text.
So let's go back to our palette, to the left here.
There is a lot of different tacks here.
But what I want I just want to text view what we call a text, a view which allows us to add text to
that view.
So I'm going to click and drag and put at the bottom here.
And next again, you notice we have the same issue here, which means we need to constrain it.
Case here.
I want this to be a constraint to the bottom like that.
Very good.
So that means it's always going to be at the bottom and I can move it right a little bit to the bottom
like this if I want to do so.
OK, very good.
So there is that constraint.
And I want also going straight to the left and to the right as such.
So it's always going to be in the middle.
And if I want to make this a little bit bigger, I can also hover over, of course, the corners there
and I can click and make it bigger.
Very good.
And as we know now, I can do all sorts of things.
For instance, if I click, which is clicked now, this text view and notice the attributes is still
there.
And what I can do is I can change some attributes.
Let's say I want to text size to be a little bit bigger so I can go ahead and look for it.
Or again, as you know, I can go and search here, just say size and then go text size.
Let's say I want this to be maybe 18, a little bit extravagant there.
So now if I go back and run again, whenever we add a new user interface element widget, in this case,
we added a text view depending on situations sometimes, and the studio will want us to reinstall and
restart the app.
That's what's happened.
That's why we have this error happening so we can go here and click from there and the app will be restarted.
And there we go.
So now we have show name and in TextView is there now de DIA of this application here is that when users
have run first run this app, as you see here, we don't want it to say something like this.
Text of what we really want is to have an empty string or an empty text view so that when they first
come to our application, there's nothing written there to do.
That is very simple.
Let's go back here, click again on TextView and says text here, says TextView.
I can just click there and delete and remove everything that is there.
There's nothing showing.
But we know that there is a text view.
So what are we going to do is we are going to dynamically show a text once we are ready to show it,
once users click on show name.
So far we've looked at the user interface.
This is what we call the user interface.
What users are going to be able to see.
Essentially, this is what we have.
In fact, let's go ahead and do a quick restart so we can see the new changes.
There we go.
So now we just have show name, but we still have the text field.
OK, so next we are going to look at the Java side of thing.
Remember, we have the XML, which is the user interface, but now whatever we created in our interface
needs to be connected to our activity.
That Java, the main activity that Java, this is where are we going to write the code that will be
triggered the moment users start interacting with our app.
So how do we do that?
Well, before we move forward, I want to make sure that our show name button has died.
That's very important, as you will see shortly.
And also our text view here has an ad and I can leave the ads as they are right now, but that's very
important.
OK, so let's go now open our main activity, Java.
So as you can see here, our main activity, like Java, is just Java code.
So I'm not going to go into a lot of details now because we just want to get something going here,
right?
We just want to build our first application.
So in this case here, instead of a uncreate method here, this is what I call a method.
There's a few lines of code.
The one I want you to look at is the SAT content view.
They set kind of you, as the name imply, will set the view, will set the user interface, will go
and get our activity main XML, this one here, and show to the user.
That's what's happening.
So whenever we run this app, what happens is that the uncreate method is called.
So this code here inside is run and then said content is called and then internally Android goes and
fetches this activity.
Underscore Main, which is our activity and scroll main.
That example we've been working on, incidentally, is what you see here.
Then how do we go ahead and connect to the show name button and the text view, which we can't see here
because we want to be able to connect to that one, to be able to retrieve information.
We want to be able to respond to whatever happens here.
How do we do that?
So that's why we have these IDs.
So each one of these widgets here, the TextView and the buttons, they have these idea.
And you can see how important these ads are, because those are the first thing that is shown for each
for any widget that we may add to our user interface.
OK, very good.
So we have that set up now back to our code, how do we pull in a button in our TextView from our user?
So first we're going to say private notice.
I'm inside of our class here, so private and then I'm going to say, button, what's happening here
is I'm going to get the representation of what a button is in Android so that we can then connected
to this button here.
So that's what's happening here.
OK, so migrating what we call the instance variable and then I'm going to name this show button as
such.
Now we're going to have an issue here because you see it's red and it's if you have it over, it's going
to say cannot resolve simple button.
We need to import class.
No problem.
I'm going to just click here and import.
And what happens now?
If you look at the top here, you can click there.
You can see there's a few imports into a few things that were added to our Java file here.
I don't want to get too much into this so far, but what is happening here is that in order for this
program work is that we need to have a few libraries, which is set of classes that already have predefined
code in this case.
Here we are importing the button class or button library, which has our button that we can use.
That's what's happening now.
We still haven't gotten the actual button.
OK, but before we move forward, let's get our text if view, which is this one here.
So I'm going to do the same thing, say private and say text notice as I type.
I have a lots of different guesses here.
OK, so this kind of helps us as we type.
So we have to type everything, as I say, text view, such notice.
There it is.
And once that is highlighted, I can actually go up and down using the arrow up and down.
Nearest text view is highlighted.
If I hit enter, I don't have to write everything myself, so it just helps me out here.
So here I'm going to say name text.
That's the name for our text view.
There we go.
So now I have those handlers, if you will, now need to be able to actually get these guys, because
now I have those handlers, as I said.
But next, I want to be able to then fetch the these widgets, OK?
What we created in our user interface inside of this main method, right after a set content, there
you see it.
And what I'm going to do, I'm going to start with our button.
So to fetch this button from our user interface, we are going to do the following can say show button.
We're going to say equal and use this method called Find View by ID.
So as you type again know, studio helps us out here.
So find if Ubaidi I can just hit enter if you find it.
And then here I'm going to say ah that ID are important and look at this or that id it knows exactly
where to get or how to get to our widget.
If I say dot look at this, there's so many different IDs but make sure we get the actual IDs we have
created.
In this case, it knows right away that we created the button ID so hit enter what's happening here.
Look, this button is the same ID click on the button as this.
So now we are saying, OK, let's go ahead and set up our show button because at this point it's just
a random button.
Now we want to connect that to the button that we created in our user interface and this is how you
do it.
OK, we're going to do the same thing with our text.
So I'm going to say name that name, text again, find by right.
Find your Ubaidi or dot id dot.
And I think we call this text view very generic, but it works.
Make sure again, that is the text in one thing you can do to make sure to see that this is the correct
ID, you can say command, click like that and then it will get you to the correct widget there.
So takes you back to activity main XML.
So if I can prove to you right now that we have actually pull in our button and our text view.
Right by doing the following.
So I'm going to use this name text there and I'm going to use a property called set text like this and
then I'm going to pass something different.
Hello, from Java like this, make sure you save.
And now I'm going to go ahead and rewrite the entire application.
I have to restart everything.
No problem.
Click there.
And look at that, hello from Java.
So this tells us, indeed, that this is working.
So now instead of showing empty TextView here, it went ahead and ran this code here.
It knows why the show button is fetched, our button, even though we're not doing anything yet.
And then it got our text view.
This one here, which is empty and we set it to this hello from Java text, which you see now says hello
from Java.
But remember, the main idea behind this application is that we want this text, something to show when
users say or click on show name button.
So we want this to be dynamic, which means we need to wire up our show name so he can actually receive
events and figure something when clicked.
How do we do that?
Well, we have a show button here.
In fact, let me go ahead and get rid of this altogether.
For now there.
I'm going to say show button again and then I'm going to set and only click listener.
What this will do, it will register this button as something that can listen for clicks or taps.
So I'm going to say button dot the moment you say dot, you say set on click listener as such.
OK, so you don't have to finish completely.
Everything just hit enter when you do that.
Next we need to pass a new object so don't worry about object or anything.
So just type what I'm saying here.
OK, we're going to learn more about this later.
So I'm going to say new on look at this when you say on and there is this view on click listener just
hit enter like that.
And once you do that, all of this happens.
What happens now is that we have this method inside where our cursor is.
It says Unclick.
So this is where we add the code that will run when the button is clicked.
Which button?
This button here.
OK, what is that we want to do?
Well, we are going to write the same code we had before here.
So I'm going to say name text.
I'm going to set the text value text attribute to say something, James.
OK, again, show button.
We say that set on Click Listener.
We wanted to start listening for clicks or for clicks or taps when users click on the button or tap
on the button.
OK, and then there is a method that will be called.
So that means when that happens, when the click happens, what is it that we want to happen.
Where we want to set the name, text our text here, which is empty in the beginning to this text here.
Right.
So say double quotes, put our text there and finish with double quotes.
That's it.
Let's go ahead and do a full run.
OK, moment of truth.
Let's go ahead and say show name and the moment you do that, hello, James is working.
All right.
So this is wonderful.
However, notice that every time we want the text to change.
Hello, James.
Let's say we want to say hello, Georgina.
We come down here, we have say, Georgina like this and Ron again.
And show name hello, Georgina, which is fine, but we have a problem here.
This is not fun because we we have to come down here in our code and write the name or change this text
here.
It's not very dynamic.
Say, wouldn't it be better if we actually had the way in which we can add or have users to add to the
text or the name they want, and then when they click show name, that name is reflected in here?
Yes, that would be even better.
All right.
So we are going to do that in the next video.