{"id":13336,"date":"2014-08-21T11:05:09","date_gmt":"2014-08-21T08:05:09","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=13336"},"modified":"2019-04-24T16:04:13","modified_gmt":"2019-04-24T13:04:13","slug":"android-listactivity-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/","title":{"rendered":"Android ListActivity Example"},"content":{"rendered":"<p><a href=\"http:\/\/developer.android.com\/reference\/android\/app\/ListActivity.html\" target=\"_blank\" rel=\"noopener noreferrer\"><code>ListActivity<\/code><\/a> is a subclass of <code>Activity<\/code> that includes a <code>ListView<\/code> object. Through <code>ListActivity<\/code> class you can create an activity in your Android application that can be connected to different data sources (query cursor or arrays) and can be displayed as a set of list items on the screen. Actually, the use of the <code>ListActivity<\/code> class provides us a more simplified way of handling the list of items because it contains a <code>ListView<\/code> by default.<\/p>\n<p>In our example we are going to show you the use of <code>ListActivity<\/code> as a screen layout in the Android apps.<\/p>\n<p>&nbsp;<\/p>\n<p>For this tutorial, we will use the following tools in a Windows 64-bit platform:<\/p>\n<ol>\n<li>JDK 1.7<\/li>\n<li>Eclipse 4.2 Juno<\/li>\n<li>Android SDK 4.1<\/li>\n<\/ol>\n<div class=\"tip\"><strong>Tip<\/strong><br \/>\nYou may skip project creation and jump directly to the <a href=\"#code\"><strong>beginning of the example<\/strong><\/a> below.<\/div>\n<\/p>\n<h2>1. Create a New Android Application Project<\/h2>\n<p>Open Eclipse IDE and go to File \u2192 New \u2192 Project \u2192 Android Application Project.<\/p>\n<p>Fill in the name of the application, the project and the package in the appropriate fields. Then click Next.<\/p>\n<p><figure id=\"attachment_13351\" aria-describedby=\"caption-attachment-13351\" style=\"width: 506px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTest_proj1.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTest_proj1.png\" alt=\"Figure 1. Create a new Android application\" width=\"506\" height=\"473\" class=\"size-full wp-image-13351\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTest_proj1.png 506w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTest_proj1-300x280.png 300w\" sizes=\"(max-width: 506px) 100vw, 506px\" \/><\/a><figcaption id=\"caption-attachment-13351\" class=\"wp-caption-text\">Figure 1. Create a new Android application<\/figcaption><\/figure><\/p>\n<p>In the next window, the \u201cCreate Activity\u201d option should be checked. The new created activity will be the main activity of your project. Then press Next button.<\/p>\n<p><figure id=\"attachment_13338\" aria-describedby=\"caption-attachment-13338\" style=\"width: 498px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTest_proj2.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTest_proj2.png\" alt=\"Figure 2. Configure the project\" width=\"498\" height=\"475\" class=\"size-full wp-image-13338\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTest_proj2.png 498w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTest_proj2-300x286.png 300w\" sizes=\"(max-width: 498px) 100vw, 498px\" \/><\/a><figcaption id=\"caption-attachment-13338\" class=\"wp-caption-text\">Figure 2. Configure the project<\/figcaption><\/figure><\/p>\n<p>In \u201cConfigure Launcher Icon\u201d window you should choose the icon you want to have in your app. We will use the default icon of android, so click Next button.<\/p>\n<p><figure id=\"attachment_12109\" aria-describedby=\"caption-attachment-12109\" style=\"width: 628px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject3.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject3.png\" alt=\"Figure 3. Configure the launcher icon\" width=\"628\" height=\"495\" class=\"size-full wp-image-12109\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject3.png 628w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject3-300x236.png 300w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/a><figcaption id=\"caption-attachment-12109\" class=\"wp-caption-text\">Figure 3. Configure the launcher icon<\/figcaption><\/figure><\/p>\n<p>Select the \u201cBlank Activity\u201d option and press Next.<\/p>\n<p><figure id=\"attachment_12110\" aria-describedby=\"caption-attachment-12110\" style=\"width: 461px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject4.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject4.png\" alt=\"Figure 4. Create the activity and select its type\" width=\"461\" height=\"501\" class=\"size-full wp-image-12110\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject4.png 461w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject4-276x300.png 276w\" sizes=\"(max-width: 461px) 100vw, 461px\" \/><\/a><figcaption id=\"caption-attachment-12110\" class=\"wp-caption-text\">Figure 4. Create the activity and select its type<\/figcaption><\/figure><\/p>\n<p>You have to specify a name for the new Activity and a name for the layout description of your app. The .xml file for the layout will automatically be created in the&nbsp;<code>res\/layout<\/code>&nbsp;folder. Finally, press Finish.<\/p>\n<p><figure id=\"attachment_12111\" aria-describedby=\"caption-attachment-12111\" style=\"width: 457px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject5.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject5.png\" alt=\"Figure 5. Create a new blank activity\" width=\"457\" height=\"469\" class=\"size-full wp-image-12111\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject5.png 457w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject5-292x300.png 292w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject5-42x42.png 42w\" sizes=\"(max-width: 457px) 100vw, 457px\" \/><\/a><figcaption id=\"caption-attachment-12111\" class=\"wp-caption-text\">Figure 5. Create a new blank activity<\/figcaption><\/figure><\/p>\n<p>You can have a look at the final structure of the project in the following image, just in case something went wrong in the previous steps.<\/p>\n<p><figure id=\"attachment_13339\" aria-describedby=\"caption-attachment-13339\" style=\"width: 321px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTest_strProj.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTest_strProj.png\" alt=\"Figure 6. The final structure of the project\" width=\"321\" height=\"568\" class=\"size-full wp-image-13339\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTest_strProj.png 321w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTest_strProj-169x300.png 169w\" sizes=\"(max-width: 321px) 100vw, 321px\" \/><\/a><figcaption id=\"caption-attachment-13339\" class=\"wp-caption-text\">Figure 6. The final structure of the project<\/figcaption><\/figure><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h2><span id=\"code\">2. Create the layout of the Main Activity<\/span><\/h2>\n<p>In order to make a screen layout, we are going to define the <code>ListView<\/code> in the UI.<\/p>\n<p>So open <code>res\/layout\/activity_main.xml<\/code>, go to the respective tab and paste the following code.<\/p>\n<p><em><u>activity_main.xml:<\/u><\/em><\/p>\n<pre class=\"brush:xml;highlight:[21,28];\">&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:paddingBottom=\"@dimen\/activity_vertical_margin\"\n    android:paddingLeft=\"@dimen\/activity_horizontal_margin\"\n    android:paddingRight=\"@dimen\/activity_horizontal_margin\"\n    android:paddingTop=\"@dimen\/activity_vertical_margin\"\n    tools:context=\".MainActivity\" &gt;\n\n    &lt;TextView\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:id=\"@+id\/mainText\"\n        android:text=\"My list\" \/&gt;\n\n    &lt;ListView \n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:layout_below=\"@+id\/mainText\"\n        android:id=\"@android:id\/list\"\n        android:background=\"#aaaaaa\" \/&gt;\n    \n    &lt;TextView\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:layout_below=\"@+id\/mainText\"\n        android:id=\"@android:id\/empty\"\n        android:text=\"There is no data\"\n        android:textStyle=\"bold\" \/&gt;\n    \n&lt;\/RelativeLayout&gt;\n<\/pre>\n<p>Now notice the highlighted lines of the above xml file. When we want to specify our <code>ListView<\/code>, it is obligatory to specify <code>@android:id\/list<\/code> at the unique identifier xml attribute (notice: not <code>@+id\/list<\/code> because an error will occur). Also we can define the background color in order to customize the desirable <code>ListView<\/code>. In addition, it is recommended to declare a <code>TextView<\/code> in order to be displayed when the <code>ListView<\/code> is out of items. For this reason <code>@android:id\/empty<\/code> is specified to the <code>id<\/code> component.<\/p>\n<p>It is important to mention that there is no need of declaring a <code>ListView<\/code> widget in the xml layout file because the <code>ListActivity<\/code> hosts one by default. In this situation, a list is displayed at the center of the screen.<\/p>\n<h2>3. Create the row layout<\/h2>\n<p>Now, we are going to create a simple layout for the rows of the <code>ListView<\/code>.<\/p>\n<p>Right click to the <code>res\/layout<\/code> folder \u2192 New \u2192 Android XML File. Specify the name of the layout, as you can see in the next image, and press Finish.<\/p>\n<p><figure id=\"attachment_13342\" aria-describedby=\"caption-attachment-13342\" style=\"width: 453px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTest_row_layout.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTest_row_layout.png\" alt=\"Figure 7. Create a new Android XML File\" width=\"453\" height=\"498\" class=\"size-full wp-image-13342\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTest_row_layout.png 453w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTest_row_layout-272x300.png 272w\" sizes=\"(max-width: 453px) 100vw, 453px\" \/><\/a><figcaption id=\"caption-attachment-13342\" class=\"wp-caption-text\">Figure 7. Create a new Android XML File<\/figcaption><\/figure><\/p>\n<p>Open <code>res\/layout\/row_layout.xml<\/code>, go to the respective tab and paste the following code.<\/p>\n<p><em><u>row_layout.xml:<\/u><\/em><\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:orientation=\"vertical\" &gt;\n    \n    &lt;TextView\n        android:id=\"@+id\/listText\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:padding=\"10dp\"\n        android:textSize=\"18sp\"\n        android:textStyle=\"bold\"\n        android:textColor=\"#ff00ff\" \/&gt;\n\n&lt;\/LinearLayout&gt;\n<\/pre>\n<p>Into this <code>LinearLayout<\/code> we will specify a simple format of the text of the list rows, so we will add a <code>TextView<\/code> element. Of course we can make a more complicated row style depending on our needs, for example we can use an <code>ImageView<\/code> etc.[ulp id=&#8217;Ja8Orb5oPKdShcXt&#8217;]<\/p>\n<h2>4. Code the Main Activity<\/h2>\n<p>At this point we will show how we can handle the <code>ListView<\/code> through the <code>ListActivity<\/code>.<\/p>\n<p>Open <code>src\/com.javacodegeeks.android.listactivitytest\/MainActivity.java<\/code>&nbsp;and paste the following code.<\/p>\n<p><em><u>MainActivity.java:<\/u><\/em><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.android.listactivitytext;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport android.os.Bundle;\nimport android.view.View;\nimport android.widget.ArrayAdapter;\nimport android.widget.ListView;\nimport android.widget.TextView;\nimport android.app.ListActivity;\n\npublic class MainActivity extends ListActivity {\n\n\tprivate TextView text;\n\tprivate List&lt;String&gt; listValues;\n\t\n\t@Override\n\tprotected void onCreate(Bundle savedInstanceState) {\n\t\tsuper.onCreate(savedInstanceState);\n\t\tsetContentView(R.layout.activity_main);\n\t\n\t\ttext = (TextView) findViewById(R.id.mainText);\n\n\t\tlistValues = new ArrayList&lt;String&gt;();\n\t\tlistValues.add(\"Android\");\n\t\tlistValues.add(\"iOS\");\n\t\tlistValues.add(\"Symbian\");\n\t\tlistValues.add(\"Blackberry\");\n\t\tlistValues.add(\"Windows Phone\");\n\n\t\t\/\/ initiate the listadapter\n\t\tArrayAdapter&lt;String&gt; myAdapter = new ArrayAdapter &lt;String&gt;(this, \n\t\t\t\tR.layout.row_layout, R.id.listText, listValues);\n \n         \/\/ assign the list adapter\n         setListAdapter(myAdapter);\n         \n\t}\n\t\n\t\/\/ when an item of the list is clicked\n\t@Override\n\tprotected void onListItemClick(ListView list, View view, int position, long id) {\n\t\tsuper.onListItemClick(list, view, position, id);\n   \n\t\tString selectedItem = (String) getListView().getItemAtPosition(position);\n\t\t\/\/String selectedItem = (String) getListAdapter().getItem(position);\n\t\t\n\t\ttext.setText(\"You clicked \" + selectedItem + \" at position \" + position); \n\t}\n\n}\n<\/pre>\n<p>Now let&#8217;s have a look at the code above. First of all we have to associate the <code>ListView<\/code> of the xml file with the <code>ListActivity<\/code>, so  the <code>setContentView()<\/code> method contains the appropriate xml layout file (<code>activity_main<\/code> in our occasion).<\/p>\n<p>After that, we should bind the <code>ListView<\/code> of the <code>ListActivity<\/code> with the data. This can be done via an adapter and more specifically through a <code>ListAdapter<\/code> interface. As you can notice, we use <code>ArrayAdapter<\/code> because the items are represented through an <code>ArrayList<\/code>. You can easily see that we use the <code>row_layout<\/code> as the layout reference of our list, as well as the id of the <code>TextView<\/code> that the <code>ListView<\/code> will be filled in. Of course Android provides us a built-in XML layout for the <code>ListView<\/code>, for example <code>simple_list_item_1<\/code>.<\/p>\n<p>Finally in order to handle the item selection, <code>onListItemClick<\/code> is called. This operation provides the selected <code>ListView<\/code> and the position of the clicked list item. Please notice the two ways of getting the name of the selected list item (through the list adapter of the list view) by indicating its position.<\/p>\n<h2>5. Run the application<\/h2>\n<p>To run our application, right click on our project \u2192 Run as \u2192 Android Application. The AVD will appear with the app loaded.<\/p>\n<p>As you can see, the <code>ListView<\/code> that is displayed on the screen includes all the list items that are defined in the <code>ArrayAdapter<\/code>. In addition, the rows of the list have the specified format of the <code>TextView<\/code> of the <code>row_layout<\/code> reference.<\/p>\n<p><figure id=\"attachment_13343\" aria-describedby=\"caption-attachment-13343\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTestAVD1.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTestAVD1.png\" alt=\"Figure 8. The Android app is loaded\" width=\"256\" height=\"359\" class=\"size-full wp-image-13343\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTestAVD1.png 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTestAVD1-213x300.png 213w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-13343\" class=\"wp-caption-text\">Figure 8. The Android app is loaded<\/figcaption><\/figure><\/p>\n<p>Now let&#8217;s choose &#8220;Android&#8221; of the list. When a list item is clicked, the callback method of the <code>onListItemClick<\/code> is initialized so the <code>text<\/code> will change appropriately.<\/p>\n<p><figure id=\"attachment_13344\" aria-describedby=\"caption-attachment-13344\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTestAVD2.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTestAVD2.png\" alt=\"Figure 9. Select a list item\" width=\"256\" height=\"359\" class=\"size-full wp-image-13344\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTestAVD2.png 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTestAVD2-213x300.png 213w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-13344\" class=\"wp-caption-text\">Figure 9. Select a list item<\/figcaption><\/figure><\/p>\n<p>If we select another list item, again the <code>onListItemClick<\/code> will be called, so the text will change again. You can notice that the text includes the name, as well as the position, of the selected item. This is happening because <code>getItemAtPosition()<\/code> of the <code>ListView<\/code> is called inside the operation of the <code>onListItemClick<\/code> interface, as you can see in the <code>MainActivity.java<\/code>.<\/p>\n<p><figure id=\"attachment_13345\" aria-describedby=\"caption-attachment-13345\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTestAVD3.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTestAVD3.png\" alt=\"Figure 10. Choose another list item\" width=\"256\" height=\"359\" class=\"size-full wp-image-13345\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTestAVD3.png 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityTestAVD3-213x300.png 213w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-13345\" class=\"wp-caption-text\">Figure 10. Choose another list item<\/figcaption><\/figure><\/p>\n<h2>Download the Eclipse Project<\/h2>\n<p>This was an example of ListActivity in Android.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here : <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ListActivityText.zip\"><strong>ListActivityText.zip<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>ListActivity is a subclass of Activity that includes a ListView object. Through ListActivity class you can create an activity in your Android application that can be connected to different data sources (query cursor or arrays) and can be displayed as a set of list items on the screen. Actually, the use of the ListActivity class &hellip;<\/p>\n","protected":false},"author":11,"featured_media":1202,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[651],"tags":[650],"class_list":["post-13336","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-listactivity","tag-onlistitemclick"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Android ListActivity Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"ListActivity is a subclass of Activity that includes a ListView object. Through ListActivity class you can create an activity in your Android application\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android ListActivity Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"ListActivity is a subclass of Activity that includes a ListView object. Through ListActivity class you can create an activity in your Android application\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2014-08-21T08:05:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-24T13:04:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Katerina Zamani\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Katerina Zamani\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/\"},\"author\":{\"name\":\"Katerina Zamani\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/94be714b6b9a82bb855c0d370c319673\"},\"headline\":\"Android ListActivity Example\",\"datePublished\":\"2014-08-21T08:05:09+00:00\",\"dateModified\":\"2019-04-24T13:04:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/\"},\"wordCount\":1033,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"keywords\":[\"onListItemClick\"],\"articleSection\":[\"ListActivity\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/\",\"name\":\"Android ListActivity Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"datePublished\":\"2014-08-21T08:05:09+00:00\",\"dateModified\":\"2019-04-24T13:04:13+00:00\",\"description\":\"ListActivity is a subclass of Activity that includes a ListView object. Through ListActivity class you can create an activity in your Android application\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Android\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"core\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"app\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/app\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"ListActivity\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/app\/listactivity\/\"},{\"@type\":\"ListItem\",\"position\":6,\"name\":\"Android ListActivity Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/94be714b6b9a82bb855c0d370c319673\",\"name\":\"Katerina Zamani\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/Katerina-Zamani-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/Katerina-Zamani-96x96.jpg\",\"caption\":\"Katerina Zamani\"},\"description\":\"Katerina has graduated from the Department of Informatics and Telecommunications in National and Kapodistrian University of Athens (NKUA) and she attends MSc courses in Advanced Information Systems at the same department. Currently, her main academic interests focus on web applications, mobile development, software engineering, databases and telecommunications.\",\"sameAs\":[\"https:\/\/www.javacodegeeks.com\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/katerina-zamani\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android ListActivity Example - Java Code Geeks","description":"ListActivity is a subclass of Activity that includes a ListView object. Through ListActivity class you can create an activity in your Android application","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/","og_locale":"en_US","og_type":"article","og_title":"Android ListActivity Example - Java Code Geeks","og_description":"ListActivity is a subclass of Activity that includes a ListView object. Through ListActivity class you can create an activity in your Android application","og_url":"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2014-08-21T08:05:09+00:00","article_modified_time":"2019-04-24T13:04:13+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","type":"image\/jpeg"}],"author":"Katerina Zamani","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Katerina Zamani","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/"},"author":{"name":"Katerina Zamani","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/94be714b6b9a82bb855c0d370c319673"},"headline":"Android ListActivity Example","datePublished":"2014-08-21T08:05:09+00:00","dateModified":"2019-04-24T13:04:13+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/"},"wordCount":1033,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","keywords":["onListItemClick"],"articleSection":["ListActivity"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/","url":"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/","name":"Android ListActivity Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","datePublished":"2014-08-21T08:05:09+00:00","dateModified":"2019-04-24T13:04:13+00:00","description":"ListActivity is a subclass of Activity that includes a ListView object. Through ListActivity class you can create an activity in your Android application","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/app\/listactivity\/android-listactivity-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Android","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/"},{"@type":"ListItem","position":3,"name":"core","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/"},{"@type":"ListItem","position":4,"name":"app","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/app\/"},{"@type":"ListItem","position":5,"name":"ListActivity","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/app\/listactivity\/"},{"@type":"ListItem","position":6,"name":"Android ListActivity Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/94be714b6b9a82bb855c0d370c319673","name":"Katerina Zamani","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/Katerina-Zamani-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/Katerina-Zamani-96x96.jpg","caption":"Katerina Zamani"},"description":"Katerina has graduated from the Department of Informatics and Telecommunications in National and Kapodistrian University of Athens (NKUA) and she attends MSc courses in Advanced Information Systems at the same department. Currently, her main academic interests focus on web applications, mobile development, software engineering, databases and telecommunications.","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/examples.javacodegeeks.com\/author\/katerina-zamani\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/13336","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=13336"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/13336\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1202"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=13336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=13336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=13336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}