Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A "projection" defines the columns that will be returned for each row
- String[] mProjection =
- {
- ProvedorPostagens.Words._ID, // Contract class constant for the _ID column name
- ProvedorPostagens.Words.WORD, // Contract class constant for the word column name
- ProvedorPostagens.Words.LOCALE // Contract class constant for the locale column name
- };
- // Defines a string to contain the selection clause
- String selectionClause = null;
- // Initializes an array to contain selection arguments
- String[] selectionArgs = {""};
- // Gets a word from the UI
- searchString = searchWord.getText().toString();
- // Remember to insert code here to check for invalid or malicious input.
- // If the word is the empty string, gets everything
- if (TextUtils.isEmpty(searchString)) {
- // Setting the selection clause to null will return all words
- selectionClause = null;
- selectionArgs[0] = "";
- } else {
- // Constructs a selection clause that matches the word that the user entered.
- selectionClause = UserDictionary.Words.WORD + " = ?";
- // Moves the user's input string to the selection arguments.
- selectionArgs[0] = searchString;
- }
- // Does a query against the table and returns a Cursor object
- mCursor = getContentResolver().query(
- UserDictionary.Words.CONTENT_URI, // The content URI of the words table
- projection, // The columns to return for each row
- selectionClause, // Either null, or the word the user entered
- selectionArgs, // Either empty, or the string the user entered
- sortOrder); // The sort order for the returned rows
- // Some providers return null if an error occurs, others throw an exception
- if (null == mCursor) {
- // Insert code here to handle the error. Be sure not to use the cursor! You may want to
- // call android.util.Log.e() to log this error.
- // If the Cursor is empty, the provider found no matches
- } else if (mCursor.getCount() < 1) {
- // Insert code here to notify the user that the search was unsuccessful. This isn't necessarily
- // an error. You may want to offer the user the option to insert a new row, or re-type the
- // search term.
- } else {
- // Insert code here to do something with the results
- }
- // Defines a list of columns to retrieve from the Cursor and load into an output row
- String[] wordListColumns =
- {
- UserDictionary.Words.WORD, // Contract class constant containing the word column name
- UserDictionary.Words.LOCALE // Contract class constant containing the locale column name
- };
- // Defines a list of View IDs that will receive the Cursor columns for each row
- int[] wordListItems = { R.id.dictWord, R.id.locale};
- // Creates a new SimpleCursorAdapter
- cursorAdapter = new SimpleCursorAdapter(
- getApplicationContext(), // The application's Context object
- R.layout.wordlistrow, // A layout in XML for one row in the ListView
- mCursor, // The result from the query
- wordListColumns, // A string array of column names in the cursor
- wordListItems, // An integer array of view IDs in the row layout
- 0); // Flags (usually none are needed)
- // Sets the adapter for the ListView
- wordList.setAdapter(cursorAdapter);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement