mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-03-29 09:09:07 +08:00
cleanup + add more comments
This commit is contained in:
@@ -3,6 +3,7 @@ class ScheduleAdapter < Android::Widget::ArrayAdapter
|
||||
@schedule = schedule
|
||||
end
|
||||
|
||||
# Instead of a generic TextView, we return a custom view for each schedule item.
|
||||
def getView(position, convertView, parent)
|
||||
titleTextView = Android::Widget::TextView.new(context)
|
||||
titleTextView.text = @schedule[position][:title]
|
||||
|
||||
@@ -85,22 +85,18 @@ class ScheduleFragment < Android::App::Fragment
|
||||
|
||||
def onCreateView(inflater, container, savedInstanceState)
|
||||
@view ||= begin
|
||||
@pos = arguments.getInt(MainActivity::MenuPosition)
|
||||
if @pos == 0 || @pos == 1
|
||||
view = Android::Widget::ListView.new(activity)
|
||||
schedule = @pos == 0 ? ScheduleDay1 : ScheduleDay2
|
||||
view.adapter = ScheduleAdapter.new(activity, Android::R::Layout::Simple_list_item_1, schedule)
|
||||
view.adapter.schedule = schedule
|
||||
view.backgroundColor = Android::Graphics::Color::WHITE
|
||||
view.divider = Android::Graphics::Drawable::ColorDrawable.new(Android::Graphics::Color::BLACK)
|
||||
view.dividerHeight = 1
|
||||
view
|
||||
else
|
||||
view = Android::Widget::TextView.new(activity)
|
||||
view.text = 'blablabla'
|
||||
view.backgroundColor = Android::Graphics::Color::RED
|
||||
view
|
||||
end
|
||||
# Retrieve the item position from the arguments. We use it to determine which schedule day we need to display.
|
||||
pos = arguments.getInt(MainActivity::MenuPosition)
|
||||
|
||||
# Create the list view with a custom adapter.
|
||||
view = Android::Widget::ListView.new(activity)
|
||||
schedule = pos == 0 ? ScheduleDay1 : ScheduleDay2
|
||||
view.adapter = ScheduleAdapter.new(activity, Android::R::Layout::Simple_list_item_1, schedule)
|
||||
view.adapter.schedule = schedule
|
||||
view.backgroundColor = Android::Graphics::Color::WHITE
|
||||
view.divider = Android::Graphics::Drawable::ColorDrawable.new(Android::Graphics::Color::BLACK)
|
||||
view.dividerHeight = 1
|
||||
view
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user