- Open the Eclipse IDE
- Select File->New->Android Project
- Enter the value for the fields.
- To create an array open the string.xml file located in value folder which is within
resource folder res
- Create an array as shown below
<string-array name="Item_Array">
<item>Item First</item>
<item>Item Second </item>
</string-array>
- Now we want to declare List View object
- Open the main.xml file located in layout folder within res folder
- Declare a List View control as
<ListView
android:id="@+id/myListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
- After creating List View contrl and String array open samples_project.java file located in src folder
- Access the list view control which is declared in string.xml as
ListView myListView = (ListView)findViewById(R.id.myListView);
- Create an object of Resources to access the string array, as
Resources myResources = getResources();
- Create an array adapter to connect the string array to the list view
final ArrayAdapter aa;
aa = new ArrayAdapter(this,android.R.layout.simple_list_item_1,myResources.getStringArray(R.array.Item_Array));
- Setting the array adpter to list view
myListView.setAdapter(aa);
- Save the application and run it