Skip to content

Instantly share code, notes, and snippets.

@jeremyd
Created March 10, 2011 06:40
Show Gist options
  • Save jeremyd/863668 to your computer and use it in GitHub Desktop.
Save jeremyd/863668 to your computer and use it in GitHub Desktop.
jruby on android thoughts ..
require 'ruboto'
ruboto_import "org.myname.example.MySQLiteOpenHelper"
#ruboto_import "org.ruboto.example.MyCursorAdapter"
#ruboto_import "org.ruboto.example.DepListActivity"
ruboto_import_widgets :LinearLayout, :TableLayout, :TableRow, :TextView, :EditText, :ScrollView
$activity.start_ruboto_activity("$dep_list_activity") do |bundle|
setup_content do |context|
# initialize SQLite
@db = MySQLiteOpenHelper.new(self, "scale-cache3", nil, 1)
@db.handle_create do |sqlitedb|
sqlitedb.execSQL("CREATE TABLE deployments ( _id INTEGER PRIMARY_KEY, nickname TEXT, cache TEXT )")
sqlitedb.close
end
output = get_deployments
linear_layout :orientation => LinearLayout::VERTICAL do
@text_view = text_view :text => "SQLITE: #{output} rows"
end
# want to use list adapter but need to figure out how ..
#
#@cursor_adapter = MyCursorAdapter.new(self, result)
#@cursor_adapter.bindView(self, self.getListView(), cursor)
#self.registerForContextMenu(self.getListView())
#self.startManagingCursor(@cursor_adapter)
end
handle_create_options_menu do |menu|
add_menu("SQL") do
# just some fun w sqlite
populate_deployments
t = get_deployments
toast t.to_s
end
add_menu("exit") do
finish
end
true
end
def self.get_deployments
cursor = @db.getWritableDatabase
result = cursor.query("deployments", nil, nil, nil, nil, nil, nil)
output = result.getCount()
cursor.close
return output
end
def self.populate_deployments
cursor = @db.getWritableDatabase
query = "INSERT INTO deployments (nickname, cache) VALUES (\"firstdeploy\",\"somedata\")"
cursor.execSQL(query)
cursor.close
end
end
@jeremyd
Copy link
Author

jeremyd commented Mar 10, 2011

ruboto gen subclass android.database.sqlite.SQLiteOpenHelper --name MySQLiteOpenHelper --method_base on

to generate the MySQLiteOpenHelper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment