Wednesday, October 23, 2013

Simple List View

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 items result into a view that's placed into the list.


File : MainActivity.java

package com.example.simplelistview;

import android.app.ListActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, PENS));
        getListView().setTextFilterEnabled(true);
        
    }
    
    static final String[] PENS = new String[]{
        "MONT Blanc",
        "Gucci",
        "Parker",
        "Sailor",
        "Porsche Design",
        "Rotring",
        "Sheaffer",
        "Waterman"
    };
    
    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        Object o = this.getListAdapter().getItem(position);
        String pen = o.toString();
        Toast.makeText(this, "You have chosen the pen: " + " " + pen, Toast.LENGTH_LONG).show();
    }
}



output:




0 comments:

Post a Comment

    Blogger news

    MIND MEDIA INNOVATIONS PVT LTD
    25/2953(2), Old GPO Building,
    Near Ayurveda College,
    Kunnumpuram,
    Thiruvananthapuram-695001
    Phone: +91 471 257 1001

    Email us @ :
    mindmediateam@gmail.com

    Total Pageviews

    Share us

    Cool Social Media Sharing Touch Me Widget by Blogger Widgets

    About

    Our hands with you, towards Android Technology