Android: Reading From a Properties File

September 21, 2012

Copy the file that you want to read from in the assets folder of your project

and use the following code to read

AssetManager am = c.getAssets();
inpStream =“”);

NOTE: I had a properties file and read it into the Java Properties object


Android: Getting Text from Selected List Item

September 19, 2012

I spent a lot of time trying to figure out how to do a very simple thing – you have a list view and you select a particular item – i wanted to get the text associated with the selected list item – it ended up being more complex than i thought ūüôā

Here is the code you will need in the AdapterView.OnItemClickListener to retrieve the textview and this code worked for me

private AdapterView.OnItemClickListener onListClick = new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView parent, View view, int position,
long id) {
Intent i = new Intent(MainActivity.this, CartoonListActivity.class);
TextView txt = (TextView) parent.getChildAt(position).findViewById(;
i.putExtra(“CartoonName”, txt.getText().toString());

Android UI – A Better Looking List View

September 18, 2012

I used the following article –¬†, to help me build a more professional looking list view.

Currently my code uses static images, as a next step i plan to use Parse to store image information and make the UI dynamic

I like the look and feel i have got now ūüôā , if you need access to the project with all the code and the graphics – let me know


Android UI – Grid Layout with Image and Text

September 17, 2012

It is a typical application interface on a mobile application Рa grid layout with images being used in grid to lead the navigation flow in the application

A combination of the GridView and an Image Adapter Class make this happen

Here is a sample of such an application running on Nexus7

Application with Image Based Grid Layout


GridView gridview = (GridView) findViewById(;
gridview.setAdapter(new ImageAdapter(this));


<GridView xmlns:android=”;



<LinearLayout xmlns:android=”;

android:layout_height=”150dp” >

android:textColorHighlight=”#656565″ >



import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ImageAdapter extends BaseAdapter {
private Context mContext;

public ImageAdapter(Context c) {
mContext = c;

public int getCount() {
return mThumbIds.length;

public Object getItem(int position) {
return null;

public long getItemId(int position) {
return 0;

// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
View v;

if (convertView == null) { // if it’s not recycled, initialize some attributes
LayoutInflater li = (LayoutInflater) mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
v = li.inflate(R.layout.grid_item, null);
TextView tv = (TextView)v.findViewById(;
ImageView iv = (ImageView)v.findViewById(;
//iv.setLayoutParams(new GridView.LayoutParams(85, 85));
iv.setPadding(8, 8, 8, 8);
} else {
v = (View) convertView;
return v;

// references to our images
private Integer[] mThumbIds = {
R.drawable.batman_96, R.drawable.caillou_96,
R.drawable.dennis_96, R.drawable.disney_96,
R.drawable.heman_96, R.drawable.looneytunes_96,
R.drawable.popeye_96, R.drawable.ppg_96, R.drawable.sd_96,
R.drawable.spm_96, R.drawable.superman_96,
R.drawable.tintin_96, R.drawable.tj_96, R.drawable.wp_96,


// references to our texts
private String[] mTextsIds = {
“Batman”, “Caillou”,
“Dennis The Menace”, “Disney”,
“He-Man”, “Looney Tunes”,
“Popeye”, “Power Puff Girls”, “Scooby Doo”,
“Spiderman”, “Superman”,
“Tintin”, “Tom and Jerry”, “Winnie the Poo”, “Woody Woodpecker”

First Parse Application

September 16, 2012

Now you know what is Parse, how to get it and you have also initialized data in the Parse cloud that is going to be used by your Android application

You have also initialized Parse in your Android application using the initialize Parse code snippet

Now building the application is simple

  • Parse requires a call to the data on the cloud and therefore as we learnt earlier, we have to make this call¬†asynchronously – you need a AsyncTask. Look at the private class¬†RemoteDataTask ¬†that extends AsyncTask
  • Learn to use the query language – it is simple :¬†
  • the rest of the steps are the same as you would do in a typical application – you have access to the data¬†dynamically, build the adapter and associate the adapter to the view, do all this in in onPostExecute method
  • Enable internet access on your AndroidManifest file –¬†<uses-permission android:name=”android.permission.INTERNET” />

public class MainActivity extends Activity {

private ListView categoryListView;
private ArrayAdapter<String> categoryListAdapter;
private List<ParseObject> categories;
private ArrayList<String> categoryList = new ArrayList<String>();

public void onCreate(Bundle savedInstanceState) {
new RemoteDataTask().execute();


public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(, menu);
return true;

private void initializeParse() {
Parse.initialize(this, “NDUawcm7DwXAkkSnuLMMiG6waq7l2RgOOu6YOpZB”,
ParseACL defaultACL = new ParseACL();
ParseACL.setDefaultACL(defaultACL, true);

private class RemoteDataTask extends
android.os.AsyncTask<Void, Void, Void> {
// Override this method to do custom remote calls
protected Void doInBackground(Void… params) {
// Gets the current list of Categories in sorted order
ParseQuery query = new ParseQuery(“Categories”);

try {
categories = query.find();
} catch (ParseException e) {
Log.e(“MainActivity:RemoteDataTask:doInBackground:Exception Retrieving Categories:”,

return null;

protected void onPostExecute(Void result) {
// Put the list of categories into the list view
for (ParseObject category : categories) {
categoryList.add((String) category.get(“Name”));
categoryListView = (ListView) findViewById(;
categoryListAdapter = new ArrayAdapter<String>(MainActivity.this,
R.layout.activity_main,, categoryList);



Getting Started with Parse

September 16, 2012
  • Register and get started with the basic plan
  • Create an application – just requires the name
  • Go to the Data Browser, choose the application and create a Class – this is equivalent to the Table in the DB
  • There are standard fields that come with every class and add additional columns you need – i just created a Name column
  • Start creating rows and add data to them – all the default columns will be auto filled, add values to the custom¬†columns

Creating Table and Data in Parse

  • Copy the Application Id and Client Key from the Overview Page – you will need these to initialize in your android application java code

Keys required for Parse Application

  • In your main activity for the application that uses parse call the following initializeParse method from your onCreate method


                    public void onCreate(Bundle savedInstanceState) {


private void initializeParse() {
Parse.initialize(this, “NDUawcm7DwXAkkSnuLMMiG6waq7l2RgOOu6YOpZB”,
ParseACL defaultACL = new ParseACL();
ParseACL.setDefaultACL(defaultACL, true);

Android and Parse

September 16, 2012

Parse: is a mobile app platform that allows you to store your applications data in the cloud. It has a full sdk that handles storage of basic data types, locations, photos, and query across them in just a few lines of code. It also comes with a data browser that lets you manage all your objects in an intuitive spreadsheet-like interface.

I plan to use parse in Android and will start with a basic plan []. In the next set of posts, i will provide examples of using Parse with Android