Tutorial: dialogfragment
Scott Moyer edited this page Nov 28, 2013
·
10 revisions
Display a dialog fragment in a Ruboto activity.
- You should have completed the Getting started with Ruboto.
- Read about fragments in the Android developer docs: http://developer.android.com/guide/components/fragments.html
- Read about the DialogFragment: http://developer.android.com/reference/android/app/DialogFragment.html
- Have an emulator running or a device with USB debugging connected.
- The emulator/device must have Android 3 or later.
- Relevant reading https://github.com/jruby/jruby/wiki/GeneratingJavaClasses
This tutorial has been tested with the following setups:
ruboto | RubotoCore | Device | Android | Android SDK | Tester |
---|---|---|---|---|---|
0.16.0.dev | 0.5.6 | Emulator | 4.1.2 | 22.2.1 | donv |
ruboto setup -y -t 15
ruboto gen app --package org.ruboto.example.dialog_fragment -t 15
cd dialog_fragment
Change src/dialog_fragment_activity.rb to this
require 'ruboto/widget'
ruboto_import_widgets :LinearLayout, :TextView
class DialogFragmentActivity
def onCreate(bundle)
super
set_title 'Dialog Fragment Example'
self.content_view =
linear_layout :orientation => :vertical, :gravity => :center do
text_view :id => 42, :text => title, :text_size => 48.0,
:gravity => :center
end
ft = getFragmentManager.beginTransaction
ft.addToBackStack(nil)
ExampleDialogFragment.new.show(ft, 'example_dialog')
end
end
class ExampleDialogFragment < android.app.DialogFragment
def onCreate(bundle)
super
@some_var = 'Ruboto does fragments!'
end
def onCreateView(inflater, container, bundle)
dialog.title = @some_var
linear_layout :orientation => :vertical do
linear_layout :gravity => :center, :layout => {:width => :fill_parent} do
text_view :text => @some_var, :id => 43, :text_size => 40.0,
:gravity => :center
end
end
end
end
rake install start