tags:

views:

704

answers:

4

Is it possible to implement the Model-View-Controller pattern in Java for Android? Or is it already implemented through Activities? Or is there a better way to implement the MVC pattern for Android?

+1  A: 

the actions, views and activies in android are the baked in way of working with the android UI and are an implementation of a model-view-viewmodel pattern, which is structurally similar (in the same family as) model view controller.

to the best of my knoweledge, there is no way to break out of this model... it can probably be done, but you would likely lose all the benefit that the existing model has, and have to rewrite your own UI layer to make it work.

Derick Bailey
A: 

There is no single MVC Pattern you could obey to. MVC just states more or less that you don't should mingle data and view, so that e.g. views are responsible for holding data or classes which are processing data are directly affecting the view.

But nevertheless, the way Android deals with classes and resources, you're sometimes even forced to follow the MVC pattern. More complicated in my oppinion are the activites which are responsible sometimes for the view but nevertheless act as an controller in the same time.

If you define your views and layouts in the xml files, load your resources from the res folder, and if you avoid more or less to mingle this things in your code, then your anyway following a MVC pattern.

Roflcoptr
+4  A: 

It's already implemented.

  • You define your user interface in various XML files by resolution/hardware etc.
  • You define your resources in various XML files by locale etc.
  • You extend clases like ListActivity, TabActivity and make use of the XML file by inflaters
  • You can create as many classes as you wish for your model
  • A lot of Utils have been already written for you. DatabaseUtils, Html,
Pentium10
A: 

Android UI creation using layouts, resources, activities and intents is an implementation of the MVC pattern. Please see the following link for more on this - http://www.cs.otago.ac.nz/cosc346/labs/COSC346-lab2.2up.pdf

arunabhdas