Endless ListView in Android

Feb 14, 2013

Some time ago, I had to implement Endless ListView in Android application. I checked different solutions, but some of them were overprogrammed or did not work well. Fortunately, I found simple solution, which solves the problem. Code snippet presenting mentioned approach, is placed below. public class EndlessScrollListener implements OnScrollListener { private int visibleThreshold = 20; private int currentPage = 0; @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } @Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (scrollState == SCROLL_STATE_IDLE) { if (listView. ...

Custom background for ActionBar and SherlockActionBar

Feb 1, 2013

When you want to set custom background for Android ActionBar or SherlockActionBar instead of playing with your styles or views, you can use the following simple code snippet. @InjectResource(R.drawable.actionbar_custom_background) private Drawable actionBarCustomBackground; public void onCreate() { getSupportActionBar().setBackgroundDrawable(actionBarCustomBackground); } In this case, Drawable object is injected using RoboGuice library and set as a background for the ActionBar. In particular cases, you can use also getActionBar() method. In Drawable object you can store an image of 1 px width and it will be stretched for 100% of width of the ActionBar. ...

Custom fonts in Android

Jan 31, 2013

Using custom fonts in Android is quite simple, but requires to do some things programmatically and cannot be done using only XML file defining the view. Let’s have a look on an example. Here we have a simple Android view file: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/custom_font" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="This is our custom font" /> </LinearLayout> We want to use custom font for the TextView element with id: custom_font. ...

Easy conversion from binary to decimal numbers in C

Jan 28, 2013

Below, you can see simple and useful code snippet presenting conversion from binary to decimal number in C language without any sophisticated operations using only strtol function. #include <stdio.h>#include <stdlib.h> int main(void) { const char binary[] = "11001"; int decimal = strtol(binary, NULL, 2); printf("binary = \"%s\", decimal = %d = 0x%02X\n", binary, decimal, decimal); return 0; } /* my output binary = "11001", decimal = 25 = 0x19 */

Android and Maven

Jan 24, 2013

Overview # Etymology # Maven, a Yiddish word meaning accumulator of knowledge. What is Maven? # Maven is a tool that can be used for building and managing any Java-based project with all its dependencies (libraries). Maven’s objectives # Making build process easy Providing uniform build system (Project Object Model) Providing quality project information Providing guidelines for best practices development Allowing transparent migration to new features Setting up Maven Android projects on MS Windows # Configuring environment # You need Eclipse Indigo or Juno installed ...

Fixing bug with dissappearing map overlay after zoom in Android

Jan 21, 2013
android, java

In Android 3.0 – HoneyComb (API 11) or higher occurs specific bug connected with map overlay. When we draw overlay on the map (e.g. routes, directions or polylines) after zooming to particular level, overlay disappear unexpectedly. We can fix this bug very easily by disabling hardware acceleration for drawing overlays. Below, you can see exemplary code snippet with map injected by RoboGuice and disabled hardware acceleration. Changing way of drawing overlays should fix the bug. ...

Adding reversed numbers

Jan 21, 2013

In this post I will show you my approach to adding reversed numbers. This problem occurred during the ACM Central European Programming Contest, in Prague in 1998. General description of the problem # Input # The input consists of N cases (equal to about 10000). The first line of the input contains only positive integer N. Then follow the cases. Each case consists of exactly one line with two positive integers separated by space. ...

Launching brand new blog

Jan 19, 2013

Hello! I’ve decided to create my own blog once again. This time I’m gonna write most of the posts only in English in order to make the articles more available and also to train my language skills (I’m Polish native speaker as some of you may already noticed). Template is clean and simple, because I’m going to focus on content - not the form. Stay tuned!