I’ve just started out building a very simple score screen for my app but nothing seems to be happening and I can’t figure out why.
The ListActivity:
public class HighScoresActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.high_scores);
ScoresDatabase db = new ScoresDatabase(this);
Cursor data = db.getHighScores();
ListAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, data, new String[] { "level" }, new int[] { R.id.level_text });
setListAdapter(adapter);
data.close();
db.close();
}
}
high_scores.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="Text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/level_text"/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
There are no error messages whatsoever, simply nothing happens.
Its not that the cursor is blank either, when I test the adapter.getCount() method, it returns ~30, which is exactly as expected.
I think all the function names are pretty much intuitive but if you need any clarification, just ask.
Any help is greatly apprechiated
There was 2 problems with my first code.
The first is as MisterSquonk pointed out, prematurely close the cursor and the database.
The second was in correctly binding the data to the views.
Here is the code of my now working solution
HighScoresActivity:
high_scores.xml:
high_scores_entry.xml:
The way I had the data originally bound made no sense.