‫Till now, we succeeded in creating the layouts.
‫The modal class and the custom adapter.
‫In this video, we'll join all of these things together in the main activity and run the application.
‫The first step is the adapter view, which is in this case a grid view.
‫I create a reference for this grid view.
‫Alt+ Enter to import the grid view class.
‫Then I'll instantiate it inside the Oncreate method view equal to find view by id.
‫The second step is the data source.
‫And in our application it's of type array list of shapes.
‫And I'll create this array list array list of type shape, shape, array list Alt+ enter import the
‫class of the array list, then a shape array equal to new array list.
‫I need to add the shape objects into this list.
‫I'll create the shapes.
‫And for the assets.
‫I prepared these shapes for shapes, cubes, sphere, cylinder and prism and the background for our
‫application.
‫Copy it and I need to paste them in the drawable folder paste and make sure that the names of these
‫images starts with small letters.
‫No numbers, no capital letters.
‫The first shape is the sphere, so I need to pass for the constructor.
‫The image and the name r dot drawable dot sphere and the name is a string.
‫I name it as sphere.
‫The second shape is.
‫Cylinder and I'll continue with other shapes.
‫And these are the four shapes I need to add them to the array list.
‫So shapes, array list, dot add, S1, S2, S3 and S4.
‫The third component or the third step is the adapter.
‫I want from you to follow my steps, because these are very important.
‫And in this order, you didn't miss anything.
‫I'll create an instance from my custom adapter.
‫And I'll initialize it here.
‫I need to pass two parameters.
‫The first one, if I go Ctrl and left Mouse or I hover the mouse, I need to pass the array list and
‫the context shapes array list that we add the four elements to it and the context get application context.
‫And we talked about context in many of of of the previous videos.
‫Grid view dot set adapter to adapter.
‫Let's run our application, save the project, run the application and here we go.
‫This is our amazing application.
‫I need to display the items in two columns, so I'll use grid view, dot set num columns and I'll make
‫it two.
‫So in the grid view you can set the number of columns using the XML or programmatically in Java or Kotlin
‫code.
‫This is how we set it using the set number columns method, you can go to the XML, you can go to the
‫main activity and here there is an attribute Num columns and I'll set it to two.
‫So either you set it in the XML or the Java code.
‫Let me run.
‫And here we go.
‫This is our grid view.
‫So congratulations, guys.
‫This is our application.
‫And one last thing I need to add is the background for this constraintlayout, which is the background
‫run.
‫And you can see this is our application.
‫I'll add a text view here.
‫And this will act as a title.
‫I'll remove this constraint for the grid view.
‫You can see this is here.
‫I'll drag this text to here in further constraints.
‫Remove this and this grid view.
‫Constraint it to here.
‫Then I can make like margin top like 24 DPI.
‫Okay.
‫This is good.
‫And the gravity of this text would be center and I'll increase the size to 48 SP or maybe 40.
‫44 is good and the style would be bold.
‫Run the application and this is better.
‫The UI looks more pretty.