ViewHolder Pattern Example

The ViewHolder Pattern allows to improve the speed of the view rendering. Every call of findViewById() is not so fast and ViewHolder can reduce it. In this pattern we reuse needed View and not call findViewById() for every ListView item. The main principle here is to create the static inner class ViewHolder that contains/hold the needed views. Below you will see the simple example.

ViewHolder Pattern Example
Continue reading

Android ListView Example

In this tutorial I will describe how to create a simple list with ListView widget. Our list will show the animals names. Also we will create the handler for on click event that will shows the selected item using Toast message.

What we need to do:

1. to initialize the ListView widget;
2. to create adapter object: in our case we will use the simple ArrayAdapter
3. to set adapter for our ListView.

listview example
Continue reading

EditText Android Example

In this post you will see the example how to use Android widget EditText in your application. The EditText is using usually when you need to get some data from user. It is like an input field in HTML.

Let’s create a simple application with layout that contains two elements: EditText and Button. The click on the button initilizes the Toast message with text from our EditText.

EditText Android Example
Continue reading

Android AutoCompleteTextView Example

In this post I will show the example how to use the AutoCompleteTextView widget in your android app. It’s very simple widget and I think we don’t need to describe it very long:)

In example below we have the simple android app where the main screen has the AutoCompleteTextView widget. When user starts to type something the widget shows the tips we have defined in our code. We will save these tips in strings resources. In real app the sources can be any (text file, sqlite and etc).


Continue reading

Error: CPU acceleration status: HAX kernel module is not installed!

Today I spent a lot of time to fix one problem with Android Emulator when I run it on Android Studio. Usually I use real device to test a application but in this case I wanted to debug on moment. I pressed the button “Run”, chose the default Nexus 5 emulator and in several seconds got the error:

D:\android\tools\emulator.exe -netdelay none -netspeed full -avd Nexus_5_API_22_x86
emulator: ERROR: x86 emulation currently requires hardware acceleration!
Please ensure Intel HAXM is properly installed and usable.
CPU acceleration status: HAX kernel module is not installed!

Continue reading