Tag Archives: android

Customize Android ListView via ListAdapter

Often I find situation where typical listview layout provided by Android’s Hello Listview tutorial is barely adequate. For instance, it does not mention anything about ListAdapter and most of the time I want to get a list that goes beyond one line text. Icon and several textfields are the norm. In this tutorial I will discuss how to create Listview that can be customized with one icons and two text fields via a ListAdapter that is customized just for that particular view. Continue reading

Create Dummy Progress Dialog in Android

Sometimes you just want to make an android app prototype with minimal logic embedded on it. Or sometimes your UI ‘designer’ just being **** and want some ‘loading’ indicator’ to do whatever he want before creating documents which I will never see anyway. In fact there are many reasons not to develop your fully functional application for user testing. In this tutorial, you will see how to create a dialog progress bar which is literally a fake progress bar.
Continue reading

Declare Global Variable In Android via android.app.Application

I am creating an application which requires login. The problem comes when I want to store the application state (e.g. whether user has login or not). Storing state in activity class is almost it is hard to make it persistent. For example, rotating the screen will literally wipe out the application state. Also when the phone keyboard slides the login form appears again and again.
Continue reading

Developed Android App gives Java NullPointer Error

Sometime when I import or export Android application using eclipse, some cryptic null pointer error pops up. The error console will only prompt some kind of ‘Local Internal Error’ or something along that line despite there is no error in the application code. The full error trace can be seen below.

[java]
java.lang.NullPointerException at com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.launch(Unknown Source) at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.doLaunch(Unknown Source) at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.launch(Unknown Source) at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:853) at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:703) at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:866) at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1069) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
[/java]

My best hypothesis, the problem lies with the running ADV which contains corrupted app references. So what I recommend is to delete the ADV instance – yes delete and not stop – before making different ADV instance. It works… kinda

Using AlertDialog in Android

This snippet is used to create and display AlertDialog which give user information and ask for the next course of action. Preferably ‘OK’ and ‘Cancel’. AlertDialog as per Android Froyo (2.2) can accomodate up to three buttons using setButton, setButton2 or setButton3. Creating an AlertDialog is fairly easy:

[java]
AlertDialog alertDialog = new AlertDialog.Builder(LoginActivity.this).create();
alertDialog.setTitle("Login information");
alertDialog.setMessage("u:" + sUserName + " p:" + sPassword);
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//show what happen when OK button is clicked
Toast.makeText(LoginActivity.this,
"Please enter your username and password",
Toast.LENGTH_SHORT).show();
}
});
alertDialog.setIcon(R.drawable.icon);
alertDialog.show();

[/java]

Notice the Toast code. If you are only want to show debug message or simple message with no user feedback, Toast is a good option.