Android ListView Tutorial

ListView application is use to show the data in the list format.

Step 1.

Create new application with any name from file menu option.

File → New Project → Application name → select API → Add Blank Activity → Activity Name → finish.

Step 2.

In activity_main.xml layout file design your application.

Add following Controls:-

listview tutorial

Step 3.

Import Package and write following coding in MainActivity.java class file.

	
    import android.widget.ArrayAdapter;
    import android.widget.ListView;


  public class MainActivity extends ActionBarActivity {

    ListView lt;
    String name[]={"Hello","Akhtra","Manzar","Shahid","Aayat"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        lt=(ListView)findViewById(R.id.listView);
        ArrayAdapter<String> ad= new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,name);
        lt.setAdapter(ad);
    }
    

Step 4. Final Output

listview tutorial

Post Your Comment