Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.redorange.database;
- import android.R.id;
- import android.app.Activity;
- import android.content.ContentValues;
- import android.database.Cursor;
- import android.database.DatabaseUtils;
- import android.database.sqlite.SQLiteDatabase;
- import android.os.Bundle;
- import android.util.Log;
- import android.widget.TextView;
- public class HeadshopDatabaseActivity extends Activity {
- HeadshopSQLHelper eventsData1;
- TextView output;
- int i = 1;
- DatabaseUtils db;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- Log.e("Creating database plz wait----------->>>>>>>>>>", "" + eventsData1);
- setContentView(R.layout.main);
- // if(i<65)
- // {
- //
- // System.out.println("Fetching");
- //
- //
- // }
- output = (TextView)findViewById(R.id.output);
- eventsData1 = new HeadshopSQLHelper(this);
- addEvent("Hello Android Event");
- Cursor cursor = getEvents();
- showEvents(cursor);
- }
- @Override
- public void onDestroy() {
- eventsData1.close();
- }
- private Cursor getEvents() {
- SQLiteDatabase db = eventsData1.getReadableDatabase();
- Cursor cursor = db.query(HeadshopSQLHelper.TABLE1, null, null, null, null,
- null, null);
- startManagingCursor(cursor);
- return cursor;
- }
- private void showEvents(Cursor cursor) {
- StringBuilder ret = new StringBuilder("saved Events \n\n");
- while (cursor.moveToNext()){
- long id = cursor.getLong(0);
- String Name = cursor.getString(1);
- String Grade = cursor.getString(2);
- String Description = cursor.getString(3);
- ret.append("id " + ":" + Name + ": " + Grade + ":"+ Description+ "\n");
- }
- output.setText(ret);
- output.moveCursorToVisibleOffset();
- }
- public long insertData(String Name, String Grade,String Description) {
- ContentValues initialValues = new ContentValues();
- initialValues.put(Name, "");
- initialValues.put(Grade, "");
- initialValues.put(Description, "");
- // initialValues.put(Id, publisher);
- //return db.insert(Hea, null, initialValues);
- return i ;
- // SQLiteDatabase db=this.getWritableDatabase();
- // ContentValues cv=new ContentValues();
- // cv.put(colDeptID, 1);
- // cv.put(colDeptName, "Sales");
- // db.insert(deptTable, colDeptID, cv);
- //
- // cv.put(colDeptID, 2);
- // cv.put(colDeptName, "IT");
- // db.insert(deptTable, colDeptID, cv);
- // db.close();
- }
- //Edited
- private void addEvent(String string) {
- SQLiteDatabase db = eventsData1.getWritableDatabase();
- ContentValues values = new ContentValues();
- //values.put(HeadshopSQLHelper._ID, 1);
- values.put(HeadshopSQLHelper.NAME, "Name");
- values.put(HeadshopSQLHelper.GRADE, "Grade");
- values.put(HeadshopSQLHelper.DESCRIPTION, "Description");
- db.insert(HeadshopSQLHelper.TABLE1, string, values);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement