Android Customizable ListView – XIC Coimbatore

Android Customizable ListView – We can design our listview for entail grace in android”  from XIC-Coimbatore

In your ADT tool create a new Android Application name as CustomListViewExample.

Open activity_main.xml drag and drop the ListView widget from composite tab.

Then open activity_main.xml page and type tools:context=”{relativePackage}.${activityClass}” in RelativeLayout.

And mainly create a new xml layout for customaizable list view. Add a widget Imageview and textview’s. change the userdefined each widget id.

click tab to MainActivity.java page. Create a global object for the ListView as lv_item.

We can manually allot the values for the list using Array for both text and images.

Here we are creating image with text based custom list view.

String[] itemname = { “Audi”, “BMW”, “Bugatti” };

Integer[] imgid = { R.drawable.audi, R.drawable.bmw, R.drawable.bugattii };

Inside the onCreate method use findviewbyid method to connect with the ListView widget xml page to the java page like follow

lv_item=(ListView) findViewById(R.id.lv_item);

 

now create our custom list view Adapter with three parameters.

 

CustomListAdapter adapter = new CustomListAdapter(this, itemname, imgid);

 

For listview set the adapter to adapter.

 

Now manually create a class for CustomListAdapter extends ArrayAdapter<String> and create a constructor with three parameters match like that MainActivity. Inside the constructor use super method for contect, layout and item.

 

public CustomListAdapter(Activity context, String[] itemname,

Integer[] imgid) {

super(context, R.layout.mylist, itemname);

// TODO Auto-generated constructor stub

 

this.context = context;

this.itemname = itemname;

this.imgid = imgid;

}

 

Override the getView method matches the particular listview items and posit ion like below

 

public View getView(int position, View view, ViewGroup parent) {

LayoutInflater inflater = context.getLayoutInflater();

View rowView = inflater.inflate(R.layout.mylist, null, true);

 

TextView txtTitle = (TextView) rowView.findViewById(R.id.item);

ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);

TextView extratxt = (TextView) rowView.findViewById(R.id.textView1);

 

txtTitle.setText(itemname[position]);

imageView.setImageResource(imgid[position]);

extratxt.setText(“Description ” + itemname[position]);

return rowView;

 

};

 

above steps are create the listview for custom items can load into the ListView widget. User can view or select any item from Listview. If array object added more values means it automatically inherits scrollview to the list.

 

 

Sample Demo Input :

Output Screen:

For More Android Application Event and other related technologies  kindly visit our Blog page.

 

Hope this blog inspires you to embrace change and grow. Whether you are an XPLORER or not, feel free to glance through our blogs and help us guide and support you in your voyage to success. Happy Learning!

0 responses on "Android Customizable ListView - XIC Coimbatore"

Leave a Message

Your email address will not be published. Required fields are marked *

© Xplore IT Corp 2017. All rights reserved. Designed by Web Design Company
Xplore WhatsApp Chat
Send via WhatsApp
X