Overview:
In this tutorial i will show how to build simple android ListView. This tutorial is all about creating listview.
What is the ListView & Why we used it?
ListView
is a view group that displays a list of
scrollable items. The list items are automatically inserted to the list using an Adapter
that pulls content from a source such as an array or database query and
converts each item result into a view that's placed into the list.So to show the content in list fashion we used ListView.
Now Creating a project in eclipse for ListView.
- Create a new project by going to File > New > Android Application Project. Fill all the details and name of your activity,I have taken it ListViewActivity.
- Copy paste all code that i have given below under your main activity called ListViewActivity.
import java.util.ArrayList;
import java.util.Arrays;
import com.rkt.listviewexample.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ListViewActivity extends Activity {
private ListView mainListView;
private ArrayAdapter<String> listAdapter;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_view);
// Find the ListView resource.
mainListView = (ListView) findViewById(R.id.Androidlist);
// Create and populate a List of Country names.
String[] countries = new String[] { "India", "Iran", "Canada",
"Turkey", "Zimbabwe", "Iceland", "Bahrain", "Australia",
"Afghanistan" };
ArrayList<String> al = new ArrayList<String>();
al.addAll(Arrays.asList(countries));
// Create ArrayAdapter using the ArrayList al.
listAdapter = new ArrayAdapter<String>(this, R.layout.simplerow, al);
//here you can add items directly in listAdapter
listAdapter.add("Malaysia");
listAdapter.add("Mexico");
listAdapter.add("France");
listAdapter.add("Israel");
listAdapter.add("Mongolia");
// Set the ArrayAdapter as the ListView's adapter.
mainListView.setAdapter(listAdapter);
}
}
- Lets start your work on UI part,you need a xml file that show our item's in list manner. So create an XML file under res folder and name it as activity_list_view.xml and paste the following code.
( Right Click on res/layout ⇒ New ⇒ Android XML File)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/Androidlist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffff00" >
</ListView>
</LinearLayout>
Output:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/Androidlist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffff00" >
</ListView>
</LinearLayout>
- Now you have to create one more xml file to show the text in listview.Create an XML file under res/layout folder and name it as simplerow.xml and type the following code under this file.This file only contains the TextView to display the text.
(Again right click on res/layout ⇒ New ⇒ Android XML File)
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rowTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:textColor="#191970"
android:textColorHighlight="#ffff00"
android:textSize="16sp"
android:textStyle="bold" >
</TextView>
android:id="@+id/rowTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:textColor="#191970"
android:textColorHighlight="#ffff00"
android:textSize="16sp"
android:textStyle="bold" >
</TextView>
- Ok,this is the time to run your project by right clicking on your project folder ⇒ Run As ⇒ Android Application.
You should see the following result in your device.
Output:
Very simple explanation!!!!!!!! Good.
ReplyDeleteListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database query and converts each item result into a view that's placed into the list.Android Training in chennai | Android Training|Android Training in chennai with placement | Android Training in velachery
ReplyDeleteAll are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
ReplyDeleteautomation anywhere training in chennai
automation anywhere training in bangalore
automation anywhere training in pune
automation anywhere online training
blueprism online training
rpa Training in sholinganallur
rpa Training in annanagar
iot-training-in-chennai
blueprism-training-in-pune
automation-anywhere-training-in-pune
Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic.
ReplyDeleteClick here:
Microsoft azure training in chennai
Click here:
Microsoft azure training in online
This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me..
ReplyDeleteData Science Training in Chennai
Data science training in bangalore
Data science online training
Data science training in pune
Data science training in kalyan nagar
selenium training in chennai
This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me..
ReplyDeletejava training in tambaram | java training in velachery
java training in omr | oracle training in chennai
java training in annanagar | java training in chennai
Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point.
ReplyDeleteBlueprism training in tambaram
Blueprism training in annanagar
Blueprism training in velachery
Very well written blog and I always love to read blogs like these because they offer very good information to readers with very less amount of words....thanks for sharing your info with us and keep sharing.
ReplyDeleteangularjs Training in bangalore
angularjs Training in btm
angularjs Training in electronic-city
angularjs online Training
angularjs Training in marathahalli
This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
ReplyDeleteData Science training in rajaji nagar | Data Science with Python training in chenni
Data Science training in electronic city | Data Science training in USA
Data science training in pune | Data science training in kalyan nagar
Well somehow I got to read lots of articles on your blog. It’s amazing how interesting it is for me to visit you very often.
ReplyDeleteangularjs-Training in velachery
angularjs Training in bangalore
angularjs Training in bangalore
angularjs Training in btm
angularjs Training in electronic-city
I am really happy with your blog because your article is very unique and powerful for new reader.
ReplyDeleteClick here:
selenium training in chennai
selenium training in bangalore
selenium training in Pune
selenium training in pune
Selenium Online Training
http://mindbendingpuzzles.blogspot.com/2014/06/android-tip-3-sharing-folder-between.html
Very impressive to read this post
ReplyDeletebest azure certification training in chennai
Wonderful post. Thanks for taking time to share this information with us.
ReplyDeleteAzure Training in Chennai
Microsoft Azure Training in Chennai
R Programming Training in Chennai
Big Data Analytics Courses in Chennai
Data Science course in Chennai
RPA course in Chennai
Azure Training in Adyar
Azure Training in Porur
You blog post is just completely quality and informative. Many new facts and information which I have not heard about before. Keep sharing more blog posts.
ReplyDeletedevops online training
aws online training
data science with python online training
data science online training
rpa online training
Very good brief and this post helped me alot. Say thank you I searching for your facts. Thanks for sharing with us!
ReplyDeleteVery good brief and this post helped me alot. Say thank you I searching for your facts. Thanks for sharing with us!
@Taskia Sultana, You broken all records of promotions. Buddy This is not a porn site Whr u promoting such content. People are fighting to solve their technical problems and u want them to watch ur porn site.
ReplyDeleteThe Blog is really Impressive one. Thanks for Posting this Blog.
ReplyDeleteData Science Training Course In Chennai | Data Science Training Course In Anna Nagar | Data Science Training Course In OMR | Data Science Training Course In Porur | Data Science Training Course In Tambaram | Data Science Training Course In Velachery
A good blog always comes-up with new and exciting information and while reading I have feel that this blog is really have all those quality that qualify a blog to be a one.
ReplyDeleteSalesforce Training | Online Course | Certification in chennai | Salesforce Training | Online Course | Certification in bangalore | Salesforce Training | Online Course | Certification in hyderabad | Salesforce Training | Online Course | Certification in pune
This is the exact information I am been searching for, Thanks for sharing the required infos with the clear update and required points. To appreciate this I like to share some useful information regarding Microsoft Azure which is latest and newest,
ReplyDeleteData Science Training In Chennai
Data Science Online Training In Chennai
Data Science Training In Bangalore
Data Science Training In Hyderabad
Data Science Training In Coimbatore
Data Science Training
Data Science Online Training
Really Thanks For Posting Such a Useful and informative article. oracle training in chennai
ReplyDeleteExcelR provides data scientist course in pune . It is a great platform for those who want to learn and become a data scientist. Students are tutored by professionals who have a degree in a particular topic. It is a great opportunity to learn and grow.
ReplyDeletedata scientist course in pune
Thanks for the Best Information Business Analytics Course
ReplyDeleteWant to set your career towards the software field? Then join hands with Infycle Technologies to make this into reality. Infycle Technologies, the best software training center in Chennai, gives the combined and best software training in Chennai, with various stages of multiple courses such as Big Data, Python, Data Science, Oracle, etc., which professional tutors will guide in the field. The Hands-on practical training and the mock interview sessions will be given to the candidates to face the interviews with full confidence. Apart from all, the candidates will be placed in the top MNC's with the highest salary package in the market. To get it all, call 7502633633 and make this happen for your happy life.Best Software Training Center in Chennai | Infycle Technologies
ReplyDeleteInfycle Technologies offers couples for care and technology in addition to Python Training in Chennai, 100% of the internship class will be prepared. After completing the training, the participants will be sent to the upper MNCs interviews. Call 750633333 to get more information and get a free display.
ReplyDeleteRecruiting solidity developers involves more than just scanning resumes and profiles. These resources are a great place to start if you have no previous experience hiring Solidity Developers.
ReplyDeleteWe can help your web or mobile app development vision to grow with high-quality, cost-effective services from our react js agency!
ReplyDelete