Last active
January 4, 2017 06:52
-
-
Save AntonioDiaz/b56c3fe1fb5a6c0b87b736934282c951 to your computer and use it in GitHub Desktop.
CursorAdapter.java example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package android.example.com.dictionaryproviderexample; | |
import android.content.ContentResolver; | |
import android.database.Cursor; | |
import android.os.Bundle; | |
import android.provider.UserDictionary; | |
import android.support.v7.app.ActionBarActivity; | |
import android.widget.ListView; | |
import android.widget.SimpleCursorAdapter; | |
public class CursorAdapter extends ActionBarActivity { | |
private static final String[] COLUMNS_TO_BE_BOUND = new String[]{ UserDictionary.Words.WORD, UserDictionary.Words.FREQUENCY }; | |
private static final int[] LAYOUT_ITEMS_TO_FILL = new int[]{ R.id.text1, R.id.text2 }; | |
Cursor cursor = null; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
ListView dictListView = (ListView) findViewById(R.id.dictionary_list_view); | |
ContentResolver resolver = getContentResolver(); | |
Cursor cursor = resolver.query(UserDictionary.Words.CONTENT_URI, null, null, null, null); | |
SimpleCursorAdapter simpleCursorAdapter = new SimpleCursorAdapter( | |
this, | |
R.layout.two_line_list_item, | |
cursor, | |
COLUMNS_TO_BE_BOUND, | |
LAYOUT_ITEMS_TO_FILL, | |
0); | |
dictListView.setAdapter(simpleCursorAdapter); | |
} | |
//TODO: cursor must be closed. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment