Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. // A "projection" defines the columns that will be returned for each row
  2. String[] mProjection =
  3. {
  4. ProvedorPostagens.Words._ID, // Contract class constant for the _ID column name
  5. ProvedorPostagens.Words.WORD, // Contract class constant for the word column name
  6. ProvedorPostagens.Words.LOCALE // Contract class constant for the locale column name
  7. };
  8.  
  9. // Defines a string to contain the selection clause
  10. String selectionClause = null;
  11. // Initializes an array to contain selection arguments
  12. String[] selectionArgs = {""};
  13.  
  14. // Gets a word from the UI
  15. searchString = searchWord.getText().toString();
  16.  
  17. // Remember to insert code here to check for invalid or malicious input.
  18.  
  19. // If the word is the empty string, gets everything
  20. if (TextUtils.isEmpty(searchString)) {
  21. // Setting the selection clause to null will return all words
  22. selectionClause = null;
  23. selectionArgs[0] = "";
  24.  
  25. } else {
  26. // Constructs a selection clause that matches the word that the user entered.
  27. selectionClause = UserDictionary.Words.WORD + " = ?";
  28.  
  29. // Moves the user's input string to the selection arguments.
  30. selectionArgs[0] = searchString;
  31.  
  32. }
  33.  
  34. // Does a query against the table and returns a Cursor object
  35. mCursor = getContentResolver().query(
  36. UserDictionary.Words.CONTENT_URI, // The content URI of the words table
  37. projection, // The columns to return for each row
  38. selectionClause, // Either null, or the word the user entered
  39. selectionArgs, // Either empty, or the string the user entered
  40. sortOrder); // The sort order for the returned rows
  41.  
  42. // Some providers return null if an error occurs, others throw an exception
  43. if (null == mCursor) {
  44. // Insert code here to handle the error. Be sure not to use the cursor! You may want to
  45. // call android.util.Log.e() to log this error.
  46.  
  47. // If the Cursor is empty, the provider found no matches
  48. } else if (mCursor.getCount() < 1) {
  49. // Insert code here to notify the user that the search was unsuccessful. This isn't necessarily
  50. // an error. You may want to offer the user the option to insert a new row, or re-type the
  51. // search term.
  52. } else {
  53. // Insert code here to do something with the results
  54.  
  55. }
  56. // Defines a list of columns to retrieve from the Cursor and load into an output row
  57. String[] wordListColumns =
  58. {
  59. UserDictionary.Words.WORD, // Contract class constant containing the word column name
  60. UserDictionary.Words.LOCALE // Contract class constant containing the locale column name
  61. };
  62.  
  63. // Defines a list of View IDs that will receive the Cursor columns for each row
  64. int[] wordListItems = { R.id.dictWord, R.id.locale};
  65.  
  66. // Creates a new SimpleCursorAdapter
  67. cursorAdapter = new SimpleCursorAdapter(
  68. getApplicationContext(), // The application's Context object
  69. R.layout.wordlistrow, // A layout in XML for one row in the ListView
  70. mCursor, // The result from the query
  71. wordListColumns, // A string array of column names in the cursor
  72. wordListItems, // An integer array of view IDs in the row layout
  73. 0); // Flags (usually none are needed)
  74.  
  75. // Sets the adapter for the ListView
  76. wordList.setAdapter(cursorAdapter);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement