Wednesday, July 6, 2011

[android-developers] Re: Converting to Fragments

I had the same problem and decided to refactor the code
to better separate Model from View/Controller.
Previously, my Activities lumped together data "logic"
and UI. But if you separate "drilling down into the data"
(separate classes) from "screens" (Activities) you can then
create smartphone style Activities for 2.x and Activities
with Fragments for 3.x.

Please look at the 2nd screenshot here

http://ecarrel.ambrosoft.com/content/local-search-0

What you see displayed as three ListFragments side by side,
used to be successive Activities (drilling down).
I moved the code responsible for eBook search
to a (non public) class Search exposing a reasonable interface.
And I made the new SearchScreen Activity with Fragments
accessing a Search object and using its interface.

It was a bit of work, but the final architecture feels much cleaner.
The Search does not know anything about the UI
and vice versa -- they can now change independently :-)

On Jul 6, 8:39 pm, Doug Gordon <gordo...@gmail.com> wrote:
> I have an app which currently builds up a stack of activities as the
> user drills down into the data. It would be an ideal candidate for using
> side-by-side fragments when run on a tablet (in landscape). But when I
> finally got around the other day to looking at what would be necessary
> to convert all that code to a fragment-based design, it looks a lot more
> complicated than I had hoped; more of a full rewrite of a lot of the
> structure. Not to mention continuing to support smartphone screens with
> the same app.
>
> So has anyone had success in morphing an existing Android 2.x app to run
> using fragments on 3.x without having to start with too much of a clean
> sheet? I could see some real ugly code and kludges creeping in if I try
> to force fragments into what I currently have.
>
> Doug Gordon

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate