I banged my head in the wall for about an hour to fix this issue.
I wrote a small function in Android that let the user send an e-mail from my application. Everything worked just fine, but when the e-mail was sent the attachment disappeared (the attachment appeared within the GMail client on the android device before sending).
Solution: use the external storage (SD Card) instead of the application cache. The GMail client probably can't access the application cache folder, buf for some reason it shows as if the attachment is OK in the client).
Thursday, October 14, 2010
Tuesday, October 12, 2010
Android's ListView performance for large list
I needed to use a large ListView however the performance of the ListView loading time was very poor. Since I've used SimpleAdapter to map the data to the layout I was forced to populate all the data when creating the SimpleAdapter.
The solution I've decided to take is creating an adapter specific for the task, which populate the data from the objects only during creation of the item's view.
This is the pseudo code (note that the object data retrieval should by lazy too):
Note: there are few examples online how to load data to ListView using threads. This wasn't my problem, and it's like killing a fly with a sledge-hammer. The loading time of a specific item was very short, the problem was that there were simply too many items to load at construction time.
The solution I've decided to take is creating an adapter specific for the task, which populate the data from the objects only during creation of the item's view.
This is the pseudo code (note that the object data retrieval should by lazy too):
public class MyObjectAdapter extends BaseAdapter {
private ArrayListmData;
private int mResource;
private LayoutInflater mInflater;
public TimeZoneDisplayAdapter(Context context, ArrayListdata,
int resource) {
mData = data;
mResource = resource;
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return mData.size();
}
@Override
public Object getItem(int position) {
return mData.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v;
if (convertView == null)
v = mInflater.inflate(mResource, parent, false);
else
v = convertView;
bindView(position, v);
return v;
}
private void bindView(int position, View view) {
MyObject o = mData.get(position);
((TextView)view.findViewById(R.id.list_item_resource_id)).setText(o.getData1());
......
......
......
}
}
Note: there are few examples online how to load data to ListView using threads. This wasn't my problem, and it's like killing a fly with a sledge-hammer. The loading time of a specific item was very short, the problem was that there were simply too many items to load at construction time.
Labels:
Android
Friday, October 8, 2010
Making TextView clickable (http)
The problem: I had a TextView which I wanted to make clickable, and open a web browser.
1. Brute force solution: change the TextView style to blue & underline. Set the onClick event to open web browser.
2. The following code:
1. Brute force solution: change the TextView style to blue & underline. Set the onClick event to open web browser.
2. The following code:
SpannableString s = SpannableString.valueOf(entryText);
URLSpan span = new URLSpan(urlText);
s.setSpan(span, 0, entryText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mTextView.setText(s);
mTextView.setMovementMethod(LinkMovementMethod.getInstance());
Labels:
Android
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.
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.
ArrayAdapteradapter = 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();
}
});
Labels:
Android
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.
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
* 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).
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).
Labels:
C#
Subscribe to:
Posts (Atom)