I'm trying to get used to using custom content providers. I've successfully managed to write a very simple application that on the press of a button adds a String to an sqlite database using a custom content provider. These database entries are then displayed in a ListView in the same activity.
I am trying to limit the number of items in the ListView to 5, but due to my lack in experience, I have no idea how to proceed.
This is what I'm using to fill the ListView
private void fillData() {
String[] from = new String[]{commentsTable.COLUMN_COMMENT, commentsTable.COLUMN_ID};
int[] to = new int[]{android.R.id.text1, android.R.id.text2};
getLoaderManager().initLoader(0, null, this);
adapter = new SimpleCursorAdapter(this, android.R.layout.two_line_list_item, null, from, to, 0);
setListAdapter(adapter);
}
I followed this tutorial http://www.vogella.com/tutorials/AndroidSQLite/article.html#tutorial-sqlite-custom-contentprovider-and-loader to write an app similar to the app in the tutorial.
I have tried using a Cursor
instead of null
but I'm getting a java.lang.NullPointerException
error because of the method .getWritableDatabase()
.