Thursday, October 4, 2012

Android custom Listview

- Kalimuthu Regaswamy
Most of android mobile applications has a listview that displays something. And its been a practise by all android developes to add a view of their taste, just by customizing the listview to what required. This blog explains how to create a custom listview in android mobile. I hope this blog will help any android application builders who need to customize listview. The view I am trying out here has a image, two textview and a multiple choice option. 

Designing Listview:

<RelativeLayout xmlns:android=""
android:layout_height="match_parent" >

android:soundEffectsEnabled="true" >

Designing custom cell:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""
android:orientation="vertical" >

android:background="@drawable/ic_launcher" />

android:textStyle="bold" />

android:textSize="15px" />


Creating pojo class:
The pojo class here gets and sets the needed objects

public class Pojo {
public String name;
public String no;
public String desc;
public String post;
private Boolean isSelected;
public Boolean getIsSelected() {
 return isSelected;
public void setIsSelected(Boolean isSelected) {
 this.isSelected = isSelected;
public String getName() {
 return name;
public void setName(String name) { = name;
public String getNo() {
 return no;
public void setNo(String no) { = no;
public String getDesc() {
 return desc;
public void setDesc(String desc) {
 this.desc = desc;
public String getPost() {
 return post;
public void setPost(String post) { = post;

Coding list adapter :I have written a list adapter which actullay adds the custom cells designed into the listview. Adapter,  here is the bridge between a ListView and the data that backs the list. The ListView can display any data provided that it is wrapped in a ListAdapter.

public class MyCustomArrayAdapter extends ArrayAdapter<Pojo> {

 private final List<Pojo> list;
 private final Activity context;
 ViewHolder viewHolder=null ;
 public MyCustomArrayAdapter(Activity context, List<Pojo> list) {
 super(context, R.layout.customlist, list);
 this.context = context;
 this.list = list;

static class ViewHolder {
 protected TextView name,no;
 protected ImageView image;
 protected CheckBox checkbox;

public View getView(final int position, View convertView, ViewGroup parent) {
 View view = null;
 if (convertView == null) {
  LayoutInflater inflator = context.getLayoutInflater();
  view = inflator.inflate(R.layout.customlist, null);
  viewHolder = new ViewHolder(); = (TextView) view.findViewById(;;; = (TextView) view.findViewById(;;
  viewHolder.image = (ImageView)         
  viewHolder.checkbox =(CheckBox) view.findViewById(;
   CompoundButton.OnCheckedChangeListener() {
    public void onCheckedChanged(CompoundButton buttonView,
    boolean isChecked) {
     Pojo element = (Pojo) viewHolder.checkbox
  } else {
   view = convertView;
  return view;

Main activity class:
This is where the list is loaded. Here I have replaced the default array adapter with the custom adapter.

public class MainActivity extends ListActivity {

public void onCreate(Bundle savedInstanceState) {
 ArrayAdapter<Pojo> adapter = new MyCustomArrayAdapter(
 MainActivity.this, getData());
public List<Pojo> getData(){
 List<Pojo> addList =new ArrayList<Pojo>();
 Pojo objectPojo=new Pojo();
 objectPojo.setDesc("android ");
 objectPojo=new Pojo();
 objectPojo.setDesc("iPhone ");

 objectPojo=new Pojo();
 objectPojo.setDesc("windows ");
 objectPojo=new Pojo();
 objectPojo.setDesc("mac ");
 return addList;
Android developers can just copy and paste the codes to get the listview customized as shown above. 


Sevaa said...

thanks for posting the codes.twas really a great to read more....

Gear Oillubricants said...

Gear oil Manufacturers CNC lubricant is prime manufacture and marketer of industrial lubricants, knitting oil, semi synthetic cutting oil, rust preventive oil, metal working fluids, hydraulic oil and CNC cutting oil.

Riya said...

This blog is very precise and informative. Have you ever thought of recording call conversations or any audio notes? If yes then, get an android app Total Recall installed and avail benefits of flexible recording. Check link-

Priya Sethuraman said...

I have been following you for a couple of months now but this is my first time commenting on a blog post. Thank you for sharing your knowledge and experience with us. Keep up the good work. Already bookmarked for future reference.
Hadoop Training in Chennai
Hadoop Training
Best Hadoop Training in Chennai
Best Hadoop Training Institute in Chennai

Hammed said...

Great site for these post and i am seeing the most of contents have useful for my Carrier.Thanks to such a useful information.Any information are commands like to share him...
SEO Company in Chennai

Shalini said...

This blog is having the general information. Got a creative work and this is very different one.We have to develop our creativity mind.This blog helps for this. Thank you for this blog. This is very interesting and useful.

digital marketing company in india

Abiya Carol said...

I just see the post i am so happy to the communication science post of information's.So I have really enjoyed and reading your blogs for these posts.Any way I’ll be replay for your great thinks and I hope you post again soon.

seo training in chennai

Anil Gupta said...

i like this valuable post. It is very informative on subject or topic.keep it up I really enjoy the blog post…
Bangalore Web Designing Company, Web Development Company Bangalore

kumar said...

Well, good information you have placed and useful too. Just now I saw your blog and it is nice and good. I love to post a comment that "The content of your post is miraculous”.I hope it will be very helpful for all. I don't have words to describe this blog. I simply want to say that absolutely very good post.
Engineering Colleges in Chennai, Mechanical Engineering Colleges in Chennai

Prasanth said...

Thank you for posting the great content…I was looking for something like this…I found it quiet interesting, hopefully and you will keep posting such blogs….Keep sharing.
UI UX Design Companies in Bangalore, Web Application Development in Bangalore

vignesjoseph said...

A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.Nice Article!
My Question:- What are different data storage options are available in Android?

SEO Training in Chennai
SEO Training Course in Chennai
Best SEO Training Institute in Chennai
SEO Training

Philips Huges said...

Thanks admin for sharing the unique content, you have done a great job

Installment loans in Mississippi
Payday loans in Mississippi
Title loans in Mississippi

Philips Huges said...

Its a wonderful post and very helpful, thanks for all this information. You are including better information regarding this topic in an effective way.Thank you so much

Installment loans in alabama
Payday loans in alabama
Title loans in alabama
Cash Advances in alabama

Ahkansha said...

This blog is having the general information. Got a creative work and this is very different one. Thanks for sharing your article. The blog is very nice.
web development training in chennai

Ahkansha said...

This blog is having the general information. Got a creative work and this is very different one. Thanks for sharing your article. The blog is very nice. web development training in chennai

Isabella Olivia said...

This information is impressive; I am inspired with your post writing style & how continuously you describe this topic.

Pawn Shop

Pawn Loans

Pawn Shops

Pawn Loan

Pawn Shop near me

ajay teja said...

Good work…unique site and interesting too… keep it up…looking forward for more updates.Good luck to all of you and thanks so much for your hard-work.
asi legal bangalore, asi legal,asi legal cochin,Shahul hameed

mcafee activate said...
mcafee livesafe retail card
mcafee activation code

E-Search Advisors Chennai said...

Nice post. Thanks for sharing this useful information.
SEO Training In Chennai
SEO Training Institute In Chennai

hero panti said... and download the Microsoft office setup online for 30 days trial.The trial version of Microsoft office setup will give you the access to all of its application but with few limitations. !