Advertisement
Guest User

Headshop database activity class

a guest
Sep 2nd, 2011
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. package com.redorange.database;
  2.  
  3. import android.R.id;
  4. import android.app.Activity;
  5. import android.content.ContentValues;
  6. import android.database.Cursor;
  7. import android.database.DatabaseUtils;
  8. import android.database.sqlite.SQLiteDatabase;
  9. import android.os.Bundle;
  10. import android.util.Log;
  11. import android.widget.TextView;
  12.  
  13. public class HeadshopDatabaseActivity extends Activity {
  14.  
  15. HeadshopSQLHelper eventsData1;
  16. TextView output;
  17. int i = 1;
  18. DatabaseUtils db;
  19. @Override
  20. public void onCreate(Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22.  
  23. Log.e("Creating database plz wait----------->>>>>>>>>>", "" + eventsData1);
  24. setContentView(R.layout.main);
  25.  
  26. // if(i<65)
  27. // {
  28. //
  29. // System.out.println("Fetching");
  30. //
  31. //
  32. // }
  33.  
  34.  
  35. output = (TextView)findViewById(R.id.output);
  36.  
  37. eventsData1 = new HeadshopSQLHelper(this);
  38. addEvent("Hello Android Event");
  39. Cursor cursor = getEvents();
  40. showEvents(cursor);
  41.  
  42. }
  43. @Override
  44. public void onDestroy() {
  45. eventsData1.close();
  46. }
  47.  
  48. private Cursor getEvents() {
  49. SQLiteDatabase db = eventsData1.getReadableDatabase();
  50. Cursor cursor = db.query(HeadshopSQLHelper.TABLE1, null, null, null, null,
  51. null, null);
  52.  
  53. startManagingCursor(cursor);
  54. return cursor;
  55. }
  56. private void showEvents(Cursor cursor) {
  57. StringBuilder ret = new StringBuilder("saved Events \n\n");
  58. while (cursor.moveToNext()){
  59. long id = cursor.getLong(0);
  60. String Name = cursor.getString(1);
  61. String Grade = cursor.getString(2);
  62. String Description = cursor.getString(3);
  63. ret.append("id " + ":" + Name + ": " + Grade + ":"+ Description+ "\n");
  64. }
  65. output.setText(ret);
  66. output.moveCursorToVisibleOffset();
  67. }
  68.  
  69. public long insertData(String Name, String Grade,String Description) {
  70. ContentValues initialValues = new ContentValues();
  71.  
  72. initialValues.put(Name, "");
  73. initialValues.put(Grade, "");
  74. initialValues.put(Description, "");
  75. // initialValues.put(Id, publisher);
  76. //return db.insert(Hea, null, initialValues);
  77.  
  78. return i ;
  79.  
  80.  
  81. // SQLiteDatabase db=this.getWritableDatabase();
  82. // ContentValues cv=new ContentValues();
  83. // cv.put(colDeptID, 1);
  84. // cv.put(colDeptName, "Sales");
  85. // db.insert(deptTable, colDeptID, cv);
  86. //
  87. // cv.put(colDeptID, 2);
  88. // cv.put(colDeptName, "IT");
  89. // db.insert(deptTable, colDeptID, cv);
  90. // db.close();
  91.  
  92.  
  93.  
  94. }
  95.  
  96. //Edited
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118. private void addEvent(String string) {
  119. SQLiteDatabase db = eventsData1.getWritableDatabase();
  120.  
  121. ContentValues values = new ContentValues();
  122. //values.put(HeadshopSQLHelper._ID, 1);
  123. values.put(HeadshopSQLHelper.NAME, "Name");
  124. values.put(HeadshopSQLHelper.GRADE, "Grade");
  125. values.put(HeadshopSQLHelper.DESCRIPTION, "Description");
  126. db.insert(HeadshopSQLHelper.TABLE1, string, values);
  127.  
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement