Building a Mobile Employee Directory – Step 1: Display a ListActivity with some data
For the source code relating to this post, checkout this Github repository.
A few years ago I came across this tutorial for Building a mobile employee directory sample with Flex and Flash Builder.
The following few posts will outline what I have learned by developing a Native Android App with similar functionality.
Employee Directory App
To start, create a new blank app in eclipse by selecting File, New Android Application Project. I have set my Application Name to “Employee Directory”, my project name to “EmployeeDirectory”, and my package name to “com.himebaugh.employeedirectory”. Click next through all the default settings. Modify MainActivity.java & activity_main.xml to the code below.
MainActivity.java
package com.himebaugh.employeedirectory; import android.app.ListActivity; import android.os.Bundle; import android.view.Menu; import android.widget.ArrayAdapter; // GOAL: Build a native android Mobile Employee Directory // ** The result is similar to the sample with Flex and Flash Builder // see http://www.adobe.com/devnet/flex/articles/employee-directory-android-flex.html // PURPOSE: Learning how to build an Android App. // Step 1: Create a blank App in eclipse. Modify it to display a ListActivity with some data. // 1) activity_main.xml (in res/layout) public class MainActivity extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String[] values = new String[] { "Employee 1", "Employee 2", "Employee 3", "Employee 4", "Employee 5", "Employee 6", "Employee 7", "Employee 8", "Employee 9", "Employee 10" }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values); setListAdapter(adapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
activity_main.xml (in res/layout)
<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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <!-- <TextView --> <!-- android:layout_width="wrap_content" --> <!-- android:layout_height="wrap_content" --> <!-- android:text="@string/hello_world" /> --> <ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" > </ListView> </RelativeLayout>
Category: Android Application Development
The code has been place on GitHub. Download at https://github.com/langhimebaugh/EmployeeDirectory/tree/Step-1