Hello frineds
This post will help you to add items to the Listview in android
Here is the output
Android comes with ListView Widget
There is two way to add item(String) to the list view
1st:
Add String Array resource in string.xml
Here is my string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, ListviewExampleActivity!</string>
<string name="app_name">ListviewExample</string>
<string-array name="ListItem">
<item >Red</item>
<item >Green</item>
<item >Blue</item>
<item >Yellow</item>
<item >Cyan</item>
</string-array>
</resources>
Now add android:entries=”@array/ListItem” to the ListView Widget
Here is my main.xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/ListItem">
</ListView>
</LinearLayout>
2nd way
Create ArrayAdapter having String Array resource and set it to the Listview
Here is my ListView.java Activity
package com.bp.listview;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ListviewExampleActivity extends Activity {
ListView l;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String arr[]={"Red","Green","Blue","Yellow","Cyan"};
l=(ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, arr);
l.setAdapter(adapter);
}
}
enjoy coding
for any query feel free to write @ bpsingh216@gmail.com
comment if it is usefull..
thanks a lot. :)
ReplyDeleteThank you.
ReplyDeleteI want to add something more in this. Say this list already exists and now I've taken EditText and i want to enter another Color in this list after pressing ADD COLOR button.
Can you please help me withh the code?
நைஸ்
ReplyDeleteNeeded to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
ReplyDeleteAndroid training in bangalore
ReplyDeleteBest Php Training Institute in Delhi
Best Java Training Institute in delhi
linux Training center in delhi
Web Designing Training center in delhi
Oracle Training Institute in delhi
blue prism Training Institute in delhi
Automation Anywhere Training center In delhi
rpa Training Institute in delhi
hadoop Training center in delhi
guys if you make your carrier and do what you want to do in your life so webtrackker is the best option to take your carrier make large
Best institute for 3d Animation and Multimedia Course training Classes
ReplyDeleteBest institute for 3d Animation and Multimedia
Best institute for 3d Animation Course training Classes in Noida- webtrackker Is providing the 3d Animation and Multimedia training in noida with 100% placement supports. for more call - 8802820025.
3D Animation Training in Noida
Company Address:
Webtrackker Technology
C- 67, Sector- 63, Noida
Phone: 01204330760, 8802820025
Email: info@webtrackker.com
Website: http://webtrackker.com/Best-institute-3dAnimation-Multimedia-Course-training-Classes-in-Noida.php
Sap fico training institute in Noida
ReplyDeleteSap fico training institute in Noida - Webtrackker Technology is IT Company which is providing the web designing, development, mobile application, and sap installation, digital marketing service in Noida, India and out of India. Webtrackker is also providing the sap fico training in Noida with working trainers.
WEBTRACKKER TECHNOLOGY (P) LTD.
C - 67, sector- 63, Noida, India.
F -1 Sector 3 (Near Sector 16 metro station) Noida, India.
+91 - 8802820025
0120-433-0760
0120-4204716
EMAIL: info@webtrackker.com
Website: www.webtrackker.com
ReplyDeleteIt seems you are so busy in last month. The detail you shared about your work and it is really impressive that's why i am waiting for your post because i get the new ideas over here and you really write so well.
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training
Thanks For Sharing The Information The information Shared Is Very valuable Please keep updating us Time Just Went On reading The article Python Online Course AWS Online Course Devops Online Course DataScience Online Course
ReplyDeleteYour info is really amazing with impressive content..Excellent blog with informative concept. Really I feel happy to see this useful blog, Thanks for sharing such a nice blog..
ReplyDeleteIf you are looking for any Data science Related information please visit our website Data science courses in Pune page!
android training center in noida sector 62
ReplyDeletedigital marketing training center in noida sector 15
python training in noida sector 63
sap sd training in noida
devops training in noida
Email marketing training course in noida sector 62
ReplyDeletedevops training in center noida
blue prism training center in noida
cloud computing training in noida sector 15
hadoop training center in noida
python training in noida sector 15
sap sd training center in noida
ReplyDeletelinux training center in noida sector 62
Email marketing training course in noida sector 15
salesforce training in noida sector 63
openstack training in noida sector 15
machine learning training in Noida sector 62