{"id":13698,"date":"2020-01-24T06:39:06","date_gmt":"2020-01-24T06:39:06","guid":{"rendered":"https:\/\/ittutorial.org\/?p=13698"},"modified":"2020-02-01T13:05:16","modified_gmt":"2020-02-01T13:05:16","slug":"android-programming-11-listview-component","status":"publish","type":"post","link":"https:\/\/ittutorial.org\/android-programming-11-listview-component\/","title":{"rendered":"Android Programming -11 Listview Component"},"content":{"rendered":"<p>Hi guys in this tutorial \u00a0we will talk about the listview component.<\/p>\n<p>In my previous tutorial, I talked about the sending and receiving parameters between two activities. If you have not read it yet, I recommend you read it first.<\/p>\n<p><a href=\"https:\/\/ittutorial.org\/android-programming-10-sending-parameters-between-two-activities\/\">https:\/\/ittutorial.org\/android-programming-10-sending-parameters-between-two-activities\/<\/a><\/p>\n<p style=\"margin: 0in;font-family: Calibri;font-size: 11.0pt\">First of all, I want to talk about the situations in which we use this component. Think of your application as you want to show a lot of text, but using textview for all of them is a waste of time and meaningless.<\/p>\n<p style=\"margin: 0in;font-family: Calibri;font-size: 11.0pt\">In such cases, we write the text to a list, thanks to the listview component in the interface of our application we have shown. For example, you are using an application where you are looking for the most suitable hotel. a lot of hotels are on the list. for each hotel we don&#8217;t use a textview. we just use one listview and an arraylist.<\/p>\n<p style=\"margin: 0in;font-family: Calibri;font-size: 11.0pt\">\n<p style=\"margin: 0in;font-family: Calibri;font-size: 11.0pt\">if we learned why we need listview component, we can start the coding of xml for listview.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout \r\n\u00a0\u00a0\u00a0 xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n\u00a0\u00a0\u00a0 xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\r\n\u00a0\u00a0\u00a0 xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\n\u00a0\u00a0\u00a0 android:layout_width=\"match_parent\"\r\n\u00a0\u00a0\u00a0 android:layout_height=\"match_parent\"\r\n\u00a0\u00a0\u00a0 tools:context=\".MainActivity\"&gt;\r\n\r\n&lt;ListView\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 android:layout_width=\"match_parent\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 android:layout_height=\"match_parent\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 android:id=\"@+id\/listview_exmple\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 android:layout_marginTop=\"20dp\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &gt;&lt;\/ListView&gt;\r\n\r\n&lt;\/RelativeLayout&gt;<\/pre>\n<p>The coding of this component is very close to the components we have seen before.\u00a0 First\u00a0 we determine the indispensabl hight and weight attribute of listview component.\u00a0\u00a0 Then we specify the id value for us to operate at java class on this component. And finally, since I want a space of 20 dp between the listview and the top of the screen. One of the most important points in XML coding is that every opened tag should be closed.<\/p>\n<pre>package com.example.mac.makale;\r\n\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.os.Bundle;\r\nimport android.widget.ListView;\r\nimport java.util.ArrayList;\r\n\r\npublic class MainActivity extends AppCompatActivity {\r\n\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0 \r\nListView listView;\r\nArrayList&lt;String&gt; arrayList;\r\n\r\n@Override\r\n\u00a0\u00a0\u00a0 protected void onCreate(Bundle savedInstanceState) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 super.onCreate(savedInstanceState);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 setContentView(R.layout.activity_main);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0\u00a0 listView=(ListView)findviewByid(R.id.listview_exmple);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0\u00a0 arrayList=new ArrayList&lt;&gt;();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0\u00a0 arrayList.add(\"Bu\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 arrayList.add(\"bir\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 arrayList.add(\"Android\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 arrayList.add(\"E\u011fitim\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 arrayList.add(\"Serisidir..\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0 }\r\n}<\/pre>\n<p style=\"margin-top: 0pt;margin-bottom: 15pt;font-family: Calibri;font-size: 11.0pt\">If we look at our Java codes.First of all, we define the global variable of listview that we will use in java encoding. We also create the Arraylist variable. We write the values that we want to show on this component in Listview and set the listview as such. In this lesson we will only see how to assign value to Arraylist. I will explain how connected the listview with arraylist in our next tutorial.<\/p>\n<p style=\"margin-top: 0pt;margin-bottom: 15pt;font-family: Calibri;font-size: 11.0pt\">If we continue to review the code, With the findviewbyid method, we connect the id value that we set in xml coding and the listview variable we define globally. then we call the arraylist&#8217;s constraction function to create it empty. And then we add the string values that we want to add to the arraylist thanks to the add method.<\/p>\n<p style=\"margin-top: 0pt;margin-bottom: 15pt;font-family: Calibri;font-size: 11.0pt\">If you want to create your arraylist with a different type of data, you have to do this during the first definition.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi guys in this tutorial \u00a0we will talk about the listview component. In my previous tutorial, I talked about the sending and receiving parameters between two activities. If you have not read it yet, I recommend you read it first. https:\/\/ittutorial.org\/android-programming-10-sending-parameters-between-two-activities\/ First of all, I want to talk about the situations in which we use &hellip;<\/p>\n","protected":false},"author":44,"featured_media":8094,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[7017,7011,7007,7005,7015,4746,7009,7008,7010,7024,3319,7021,7026,7016,7022,7025,7018,7019,7020,7006,7014,7023,7012,7013],"class_list":["post-13698","post","type-post","status-publish","format-standard","has-post-thumbnail","","category-android","tag-android-app-development","tag-android-app-development-software","tag-android-button-color-xml","tag-android-coding","tag-android-development-basics","tag-android-programming","tag-android-programming-language","tag-android-programming-tutorial","tag-android-programming-with-java","tag-android-project","tag-android-studio","tag-android-studio-basic-example","tag-android-studio-basic-projects","tag-android-studio-first-app","tag-android-studio-lessons","tag-android-studio-projects","tag-android-studio-tutorial","tag-android-studio-tutorial-for-beginners","tag-android-studio-tutorial-point","tag-android-xml-coding","tag-create-mobile-app-without-coding","tag-java-android-developer","tag-mobil-app-maker","tag-mobile-application-make"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/featured-860x280.png","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/13698","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/users\/44"}],"replies":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/comments?post=13698"}],"version-history":[{"count":1,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/13698\/revisions"}],"predecessor-version":[{"id":13699,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/13698\/revisions\/13699"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media\/8094"}],"wp:attachment":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media?parent=13698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/categories?post=13698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/tags?post=13698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}