Created
March 10, 2011 06:40
-
-
Save jeremyd/863668 to your computer and use it in GitHub Desktop.
jruby on android thoughts ..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ruboto gen subclass android.database.sqlite.SQLiteOpenHelper --name MySQLiteOpenHelper --method_base on
to generate the MySQLiteOpenHelper