In the world of "pure" Object Oriented Programming, there is this (age-old) pattern, MVC, model / view / controller.

http://en.wikipedia.org/wiki/Model–View–Controller

It means storing the data in some kind of somewhat centralized place (Model), with Views accessing this data when needed. This is good, since you don't have to "push" data into each view that might need it.

As it turns out, you can easily use this pattern (partly) in Android.

Since Activity is a subclass of Context, and Views are typically attached to Activities, you can:

- Store data in your Activity subclass (that's how it's usually done anyway)
- Call getContext from methods in your View subclass
- Cast the context to your subclass of Activity
- Use the activity to get the data

class MyActivity extends Activity {

List<Item> getMyDataItems() {
return mDataItems;
}

private List<Item> mDataItems;
}

class MyView extends View {

void blah () {

Context context = getContext();
MyActivity activity = (MyActivity) context;

List<Item> data = activity.getMyDataItems();

}

-- Kostya

21.11.2010 3:46, hari пишет:
Hi guys,

I have a need where i must pass some values from an Activity to
another file which extends View class (instead of Activity) .... Its
not the normal passing of values from one activity to another...

In my Activity,i will pass some co-ordinate values to the class that
extends View... In this class,i will draw an image and place points
over the image on the required co-ordinates... But , the problem is ,i
cant send values using Intent ...

Is there any way to do this?? Pls reply ASAP....

Thanks



--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to