.
MyBuddies101: ListView String Resources
The Android project in this tutorial was written and compiled on the online platformwww.programmr.com
The reader that follows this tutorial series does not have to install anything except a web browser (preferably Chrome) and registered to www.programmr.com .
|
1) Create New Android Project
Project Name: MyBuddies
New Project Created.
2) Set minSdk (Optional)
We do this just to get a more recent look of our apps
|
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.MyBuddies"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<activity android:name="MyBuddies"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="15" />
</manifest>
|
3) Set the ListView string resources
Add a string array resources under the name buddies_array
|
res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">MyBuddies</string>
<string-array name="buddies_array">
<item>Superman</item>
<item>Spiderman</item>
<item>Batman</item>
<item>Ironman</item>
<item>Ultraman</item>
<item>Pacman</item>
<item>Roboman</item>
</string-array>
</resources>
|
4) Edit Layout File (main.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/btn_addbuddy"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Add Buddy"
/>
<ListView
android:id="@+id/lvw_buddies"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:entries="@array/sports_array"
/>
</LinearLayout>
|
OUTCOME.
In this exercise, we do not have to edit the Controller File (MyBuddies.java) at all.
Android automatically loads the listview items from the string resources.
|
No comments:
Post a Comment