Welcome to part 3 of my Samsung Mobile SDK Tutorial. In this tutorial I will cover Samsung SLook, ListActivity, SimpleAdapter, ListView, Intents and much more.
We’ll be creating a ListView. It will be populated with list items that are defined by a SimpleAdapter. After the ListView is created, when an item is clicked an Intent will be created that will send the user to a new Activity.This tutorial should make the purpose of ListViews and Intents very clear.
If you like videos like this it helps if you tell Google+ with a click here [googleplusone]
Donโt forget to check out the Samsung Smart App Challenge and if it is still November 2013, donโt forget to sign up to win a Samsung Galaxy Note 3, or Samsung Galaxy Gear Smart Watch on my site.
Code from the Video with Transcriptions for Translation
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="@string/hello_world" tools:context=".MainActivity" /> <!-- tools:context=".MainActivity" Used to pick the right theme to show for the layout --> </RelativeLayout>
package com.samsung.android.example.slookdemos; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ListView; import android.widget.SimpleAdapter; public class SlookActivity extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // We use SimpleAdapter to bind the static data provided // by getData() to the Listview object which is bound to the // TextView in activity_main.xml // You pass the following to SimpleAdapter // The Context, a list containing the data, // simple_list_item_1 is a standard Android row layout, // list of column names that will be added to the map, // and the TextViews that should display the data setListAdapter(new SimpleAdapter(this, getData(), android.R.layout.simple_list_item_1, new String[] { "title" }, new int[] { android.R.id.text1 })); // Get the activities ListView widget and enable filtering // for the ListView so that a keyboard can select an item getListView().setTextFilterEnabled(true); } // Returns a List filled with Maps which are key value pairs private List<Map<String, Object>> getData() { List<Map<String, Object>> myData = new ArrayList<Map<String, Object>>(); // addItem() below receives the List of Maps, the title // for the List that is displayed on the screen and // the Intent fired when a list item is clicked. addItem(myData, "1. Information", activityIntent("com.samsung.android.example.slookdemos .InformationActivity")); addItem(myData, "2. WritingBuddy", activityIntent("com.samsung.android.example.slookdemos .WritingBuddyActivity")); addItem(myData, "3. AirButton", activityIntent("com.samsung.android.example.slookdemos .AirButtonActivity")); addItem(myData, "4. SmartClip", activityIntent("com.samsung.android.example.slookdemos .SmartClipActivity")); addItem(myData, "5. PointerIcon", activityIntent("com.samsung.android.example.slookdemos .PointerIconActivity")); return myData; } // Create an Intent which will be the class that is called // when the user clicks on a list item. private Intent activityIntent(String componentName) { Intent result = new Intent(); // Sets the class for this Intent result.setClassName(this, componentName); return result; } // Receive a List that adds the title and Intent to a Hashmap // which is then added to the List private void addItem(List<Map<String, Object>> data, String name, Object intent) { Map<String, Object> item = new HashMap<String, Object>(); item.put("title", name); item.put("intent", intent); data.add(item); } // When the list item is clicked the corresponding class (Activity) // is executed @Override @SuppressWarnings("unchecked") protected void onListItemClick(ListView l, View v, int position, long id) { Map<String, Object> map = (Map<String, Object>) l.getItemAtPosition(position); Intent intent = (Intent) map.get("intent"); startActivity(intent); } }
package com.samsung.android.example.slookdemos; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ListView; import android.widget.SimpleAdapter; // WritingBuddyActivity works in exactly the same way // that the SlookActivity ListActivity works public class WritingBuddyActivity extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // We use SimpleAdapter to bind the static data provided // by getData() to the Listview object which is bound to the // TextView in activity_main.xml // You pass the following to SimpleAdapter // The Context, a list containing the data, // simple_list_item_1 is a standard Android row layout, // list of column names that will be added to the map, // and the TextViews that should display the data setListAdapter(new SimpleAdapter(this, getData(), android.R.layout.simple_list_item_1, new String[] { "title" }, new int[] { android.R.id.text1 })); // Get the activities ListView widget and enable filtering // for the ListView so that a keyboard can select an item getListView().setTextFilterEnabled(true); } // Returns a List filled with Maps which are key value pairs private List<Map<String, Object>> getData() { List<Map<String, Object>> myData = new ArrayList<Map<String, Object>>(); addItem(myData, "1. EditText", activityIntent("com.samsung.android.example.slookdemos.WritingBuddyEditTextActivity")); addItem(myData, "2. ViewGroup", activityIntent("com.samsung.android.example.slookdemos.WritingBuddyViewGroupActivity")); return myData; } // Create an Intent which will be the class that is called // when the user clicks on a list item. private Intent activityIntent(String componentName) { Intent result = new Intent(); result.setClassName(this, componentName); return result; } // Receive a List that adds the title and Intent to a Hashmap // which is then added to the List private void addItem(List<Map<String, Object>> data, String name, Object intent) { Map<String, Object> item = new HashMap<String, Object>(); item.put("title", name); item.put("intent", intent); data.add(item); } // When the list item is clicked the corresponding class (Activity) // is executed @Override @SuppressWarnings("unchecked") protected void onListItemClick(ListView l, View v, int position, long id) { Map<String, Object> map = (Map<String, Object>) l.getItemAtPosition(position); Intent intent = (Intent) map.get("intent"); startActivity(intent); } }
Information on my Contest
The Requirements for Entering the Samsung Smart App Challenge can be found here : http://developer.samsung.com/ssac2013/note/main.do
Iโm very excited to provide you with my Samsung Mobile SDK Tutorial! Over the next few videos I cover: the Samsung Mobile SDK.
Thanks to the nice people at Samsung and the Samsung Smart App Challenge, who are giving away $1.1 Million in prizes.
Iโll also be offering a give away. Between now and November the 30th, sign up for a free Samsung developer account at http://developer.samsung.com/signup and you will be eligible to win a Samsung GALAXY Note 3 device or one of three Samsung GALAXY Gear smart watches. I will choose a winner at random.
After you signup for the Samsung developer account, leave a comment on my website stating that you signed up. That is all!
hello admin,
how many languages you have used to make this wonderful website..
Hello, The whole site was built using WordPress. I have a ton of tutorials on it if you are interested. I hope you enjoy them.
I signed up to the samsung developer program!
Good luck in the contest ๐
hello,
I signed up ๐
Good luck ๐
Hi, I signed up
Good luck ๐