Sha256: c2356bd991027d1f4d8da4bd3410e3273da2a4146c81893913656744a92f0384

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 KB

Contents

require 'ruboto/activity'
require 'ruboto/widget'

ruboto_import_widgets :LinearLayout, :ListView, :TextView

class SubclassOfArrayAdapter < Java::AndroidWidget::ArrayAdapter
  def getView(position, convert_view, parent)
    puts "IN get_view!!!"
    @inflater ||= context.getSystemService(Context::LAYOUT_INFLATER_SERVICE)
    row = convert_view ? convert_view : @inflater.inflate(mResource, nil)
    row.findViewById(mFieldId).text = "[#{get_item(position)}]"
    row
  rescue Exception
    puts "Exception getting list item view: #$!"
    puts $!.backtrace.join("\n")
    convert_view
  end
end

class Java::AndroidWidget::ArrayAdapter
   field_reader :mResource, :mFieldId
end

class SubclassActivity
  def on_create(bundle)
    super
    setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ')

    adapter = SubclassOfArrayAdapter.new(self, android.R.layout.simple_list_item_1, AndroidIds::text1, ['Record one', 'Record two'])

    self.content_view =
        linear_layout :orientation => LinearLayout::VERTICAL do
          @text_view = text_view :text => 'What hath Matz wrought?', :id => 42
          @list_view = list_view :adapter => adapter, :id => 43,
              :on_item_click_listener => proc{|_,view,_,_| @text_view.text = view.findViewById(AndroidIds::text1).text}
        end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ruboto-0.10.1 test/activity/subclass_activity.rb
ruboto-0.10.0 test/activity/subclass_activity.rb
ruboto-0.10.0.rc.1 test/activity/subclass_activity.rb
ruboto-0.10.0.rc.0 test/activity/subclass_activity.rb