Monday, August 23, 2010

AlertDialog with single selection & no radio button

Current Android version AlertDialog.Builder default behavior of "setSingleChoiceItems" creates a list with radio buttons from which you can select.

I wanted to get this list without the radio button. After digging a bit in AlertDialog.Builder & AlertController.AlertParams I found the solution: instead of using setSingleChoiceItems use setAdapter.


ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.select_dialog_item, itemActionsList);
dialog.setAdapter(adapter,
new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// Do something
arg0.dismiss();
}
});

Android hangs: "Waiting For Debugger"

I developed an application that worked just fine, and then it started to hang with the message: "Waiting For Debugger". Even when I disconnected the device from the computer the application insisted that it's waiting for the debugger...

Solution:
1. Restart Eclipse [it's probably not needed].
2. Restart the Android device.

Friday, August 20, 2010

Android requires .class compatibility set to 5.0. Please fix project properties.

I've created a new workspace in Eclipse & imported an Android project.

* Issue #1:
Android requires .class compatibility set to 5.0. Please fix project properties.

* Solution:
1. Fix project:
Package Explorer ->
Right click the project ->
"Android Tools" -> "Fix Project Properties"
2. Restart Eclipse:
"File" -> "Restart"

* Issue #2: The following error appears many times
The method xyz() of type ABC must override a superclass method

* Solution:
1. Fix the project again:
Package Explorer ->
Right click the project ->
"Properties" -> "Java Compiler" -> "Compiler Compliance Level" = 1.6

Monday, August 16, 2010

DataView RowFilter performance

I needed to use DataView but the performance I got was very poor. Searching the web I found this resource which explains the root cause for this issue: after each RowFilter the DataView is re-indexed.

Searching a bit more yield the answer from Microsoft: don't use RowFilter if you don't have to. Use FindRows.

For my scenario, using FindRows instead of Row filter resulted in at least factor of 6 improvement (i.e. 1 second instead of 6).

Thursday, August 12, 2010

Eclipse hangs during building Android projects workspace

Problem: Eclipse kept on hanging during auto-building Android projects.
I found a resource which said (escalating solutions):
1. Clean the projects.
2. Create a new workspace & import all projects.
3. Reinstall Eclipse

After trying 1 & 2, I found the following weird solution:
- Remove the auto-build (Project => Build Automatically). Kill the Eclipse (since it hangs...)
- Restart Eclipse.
- Delete the 'gen' folder of all the projects (using the Package Explorer)
- Project => Clean (clean all projects)
- Build the projects

Don't know why it worked (at least until now).

Android/Eclipse: Project 'MyProject' is missing required source folder: 'gen'

I'm having lots of problems with my Eclipse (when I'll solve them I'll write about it).

Anyhow, after creating a new project in a new workspace I get the following error:
Project 'MyProject' is missing required source folder: 'gen'
After building the project there's a second error:
The project cannot be built until build path errors are resolved

A temporary solution: in the Package Explorer delete gen folder. Rebuilding the project again will fix the problem. Why it's temporary? you'll have to do it with every new project.

Thursday, August 5, 2010

Starting android calculator programmatically

Here goes:

public static final String CALCULATOR_PACKAGE =
"com.android.calculator2";
public static final String CALCULATOR_CLASS =
"com.android.calculator2.Calculator";

public static void OpenCalculator(Context context) {
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);

i.setFlags(
Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
i.setComponent(new ComponentName(
CALCULATOR_PACKAGE,
CALCULATOR_CLASS));
context.startActivity(i);
}