O'Reilly logo

Hello, Android, 4th Edition by Ed Burnette

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Data Binding

Data binding allows you to connect your model (data) to your view with just a few lines of code. To demonstrate data binding, we’ll modify the Events example to use a ListView that’s bound to the result of a database query. First, we need to make the MainActivity class extend ListActivity instead of Activity:

eventsv2/src/main/java/org/example/events/MainActivity.java
 
import​ android.app.ListActivity;
 
// ...
 
public​ ​class​ MainActivity ​extends​ ListActivity {
 
// ...
 
}

Next, we need to change how the events are displayed in the MainActivity.showEvents method:

eventsv2/src/main/java/org/example/events/MainActivity.java
 
import​ android.widget.SimpleCursorAdapter;
 
// ...
 
private​ ​static​ ​int​​[]​ TO = { R.id.rowid, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required