Most of the mobile applications will use List view. It is simple to create one using ListActivity class in Android.
ListActivity has a default layout that consists of a single, full-screen list in the center of the screen. However,we can customize the screen layout by setting our own view layout with setContentView() in onCreate().
To do this, our layout MUST contain a ListView object with the id "@android:id/list". ( NOT android:id="@+id/list" ).
if we define a ListView with the android:id attribute set to @+id/list then it will throw below RuntimeException
java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
I am using ArrayAdapter to render the list. Data to be displayed in the List. We can use lists or arrays of custom objects.
1). To render it using default layout we need to create a <TextView> in the layout xml file.
Using ArrayAdapter we can render the data in List view.
2). To render the List inside a Linear Layout, we need to have a <TextView> and a <ListView> with the id "@android:id/list" as stated at the beginning of this tutorial.
The ArrayAdapter constructor will take different arguments in this case,
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
We need to pass the id of the TestView element additionally.