This shows you the differences between two versions of the page.
mdad:laboratoare:05 [2020/10/07 13:55] 127.0.0.1 external edit |
mdad:laboratoare:05 [2021/01/12 11:15] (current) ioana_maria.culic |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Laboratorul 05. ===== | + | ===== Lab 05 - Lists ===== |
=== LISTS === | === LISTS === | ||
In android, an adapter is a bridge between UI component and data source that helps us to fill data in the UI component. It holds the data and send the data to adapter view then view can takes the data from the adapter view and shows the data on different views like as list view, grid view, spinner etc\\ | In android, an adapter is a bridge between UI component and data source that helps us to fill data in the UI component. It holds the data and send the data to adapter view then view can takes the data from the adapter view and shows the data on different views like as list view, grid view, spinner etc\\ | ||
Line 17: | Line 17: | ||
====== Exercises : ====== | ====== Exercises : ====== | ||
- | **Ex 0** Make a new project and do not generate a XML file. \\ | + | **Ex 1** Create a new project and follow the next tutorial http://abhiandroid.com/ui/baseadapter-tutorial-example.html. |
+ | |||
+ | |||
+ | **Ex 2** Make a new project and do not generate a XML file. \\ | ||
Add the next image into the project\\ | Add the next image into the project\\ | ||
{{:mdad:laboratoare:lab5_car_icon.png?150|}} | {{:mdad:laboratoare:lab5_car_icon.png?150|}} | ||
- | **Ex 1** (If you have generated a xml file in the ex 0, delete it) Add a new xml file named activity_main.xml and make it a LinearLayout with __width match_parent__ and__ height wrap_content__ with the __orientation vertical__. In it, add a **ListView** with __width and height match_parent__ and an id android:id="@+id/lv_list_cars"\\ | + | **Ex 3** (If you have generated a xml file in the ex 0, delete it) Add a new xml file named activity_main.xml and make it a LinearLayout with __width match_parent__ and__ height wrap_content__ with the __orientation vertical__. In it, add a **ListView** with __width and height match_parent__ and an id android:id="@+id/lv_list_cars"\\ |
- | **Ex 2** Create another xml file (a LinearLayout ) named list_item.xml. The __orientation__ shoud be __horizontal__ and the __width and the height__ shoud be wrap___content__.\\ | + | **Ex 4** Create another xml file (a LinearLayout ) named list_item.xml. The __orientation__ shoud be __horizontal__ and the __width and the height__ shoud be wrap___content__.\\ |
In the LinearLayout, add an **ImageView**(with id iv_image_element) and a **TextView**(with id tv_name_element), both with width and height wrap_content. | In the LinearLayout, add an **ImageView**(with id iv_image_element) and a **TextView**(with id tv_name_element), both with width and height wrap_content. | ||
\\ | \\ | ||
- | **Ex 3** In the MainActivity.java file create another 2 classes (not in class MainActivity): __class Car__ with a String name, and an int imageResource and another __class__ named __TagCar__ with a TextView name and an ImageView image. | + | **Ex 5** In the MainActivity.java file create another 2 classes (not in class MainActivity): __class Car__ with a String name, and an int imageResource and another __class__ named __TagCar__ with a TextView name and an ImageView image. |
\\ | \\ | ||
- | **Ex 4** Create a new java file named CarAdapter which extends BaseAdapter. In it, add an __Activity object named context__, and an __ArrayList of Car named cars.__\\ | + | **Ex 6** Create a new java file named CarAdapter which extends BaseAdapter. In it, add an __Activity object named context__, and an __ArrayList of Car named cars.__\\ |
Create a constructor which receive an Activity and initialize the context, and the cars ArrayList, also add the next function addCar: | Create a constructor which receive an Activity and initialize the context, and the cars ArrayList, also add the next function addCar: | ||
Line 49: | Line 52: | ||
| | ||
\\ | \\ | ||
- | **Ex 5** **Implement** the 4 methods, and in the getView function add this text: | + | **Ex 7** **Implement** the 4 methods, and in the getView function add this text: |
public View getView(int i, View view, ViewGroup viewGroup) { | public View getView(int i, View view, ViewGroup viewGroup) { | ||
View element; | View element; | ||
Line 67: | Line 70: | ||
| | ||
- | **Look in Course 4 - List, adapters, recycling slides 29-31 and tell the teaching assistant if this method is efficient or not (if it's not, make it efficient).** | + | **Look in Course 4 - List, adapters, recycling slides and tell the teaching assistant if this method is efficient or not (if it's not, make it efficient).** |
\\ | \\ | ||
- | **Ex 6** In MainActivity class, in the onCreate function, connect the ListView from the java to the xml (TODO 1)\\ | + | **Ex 8** In the MainActivity class, in the onCreate function, connect the ListView from the java to the xml (TODO 1)\\ |
TODO 2: initializate the object carAdapter(2)\\ | TODO 2: initializate the object carAdapter(2)\\ | ||
TODO 3: set the carAdapter adapter for list of cars (3).\\ | TODO 3: set the carAdapter adapter for list of cars (3).\\ | ||
Line 93: | Line 96: | ||
RUN THE APP | RUN THE APP | ||
\\ | \\ | ||
- | **Ex 7** In the activity_main.xml, in the linearLayout , add another LinearLayout (width match parent and height wrap_content, orientation horizontal) and add in it an EditText (with id ed_new_car, height wrap_content and width 200dp) and a Button (id b_add_car, width and height wrap_content) | + | **Ex 9** In the activity_main.xml, in the linearLayout , add another LinearLayout (width match parent and height wrap_content, orientation horizontal) and add in it an EditText (with id ed_new_car, height wrap_content and width 200dp) and a Button (id b_add_car, width and height wrap_content) |
- | + | ||
- | **Ex 8** In MainActivity, in onCreate function, connect the EditText and the Button from the java to the XML file. Set an onClickListener on the button: when clicked, get the Text from the editText and convert it to String, and add a new car in the carAdapter using the name from the editText. After that, set the editText's text to "". | + | |
- | + | ||
- | **Ex 9** Create a new project and follow the next tutorial http://abhiandroid.com/ui/baseadapter-tutorial-example.html. | + | |
- | **Ex 10** Create a README file in which explain | + | **Ex 10** In MainActivity, in onCreate function, connect the EditText and the Button from the java to the XML file. Set an onClickListener on the button: when clicked, get the Text from the editText and convert it to String, and add a new car in the carAdapter using the name from the editText. After that, set the editText's text to "". |
- | - what challenges you had if you didn't finish the exercises | + | |
- | - describe the 2 projects (project 1 - ex 0-8, project 2 - ex 9) and what you have learned from them | + | |
- | - make a screenshot of the application and include it in the project | + | |
- | Add the first project (ex 0-8) and the README file on Github/ Bitbucket and send the link of the project to the teaching assistant. | ||