If you need a global object like that, the best thing to do is to hold
a reference to it in your application class object, which you can
access from
any activity via getApplication(); Just be sure that whatever you are
sticking in that map isn't keeping a strong reference to the activity
context, otherwise you'll start leaking activities across lifecycle
events.


Jonathan




On Jan 4, 1:07 am, jennifer <[email protected]> wrote:
> I am using a SortedMap in a calss that extends SimpleCursoradapter. can i
> acess that map from another class that extends ListActivity.
>
> The code im using is given below.
>
> *
>
> public* *class* ListContacts *extends* ListActivity {
>
> ListAdapter lAdapter;
>
> @Override
>
> *public* *void* onCreate(Bundle savedInstanceState) {
>
> *super*.onCreate(savedInstanceState);
>
> setContentView(R.layout.*activitylist*);
>
> //
>
> /**
>
> *
>
> * Use the ContentResolver instance to query the database and return a
>
> * Cursor with the contacts list. The query is performed against the URI
>
> * stored in ContactsContract.Contacts.CONTENT_URI.
>
> */
>
> Cursor cursor = getContentResolver().query(
>
> ContactsContract.Contacts.*CONTENT_URI*, *null*,
>
> ContactsContract.Contacts.*HAS_PHONE_NUMBER* + " = 1", *null*,null);
>
> startManagingCursor(cursor);
>
> // start mappings
>
> String[]  columns = *new* String[] { ContactsContract.Contacts.*DISPLAY_NAME
> * };
>
> *int*[] names  = *new* *int*[] { R.id.*contact_name* };
>
> lAdapter = *new* ImageCursorAdapter(*this*, R.layout.*main*, cursor, columns
> ,names);
>
> @Override
>
> *protected* *void* onListItemClick(ListView l, View v, *int* position, *long
> * id) {
>
> *super*.onListItemClick(l, v, position, id);
>
> }
> } //  end of class ListContacts
>
> *
>
> public* *class* ImageCursorAdapter *extends* SimpleCursorAdapter {
>
> *private* Cursor c;
>
> *private* Context context;
>
> SortedMap<String, String> phoneNumberMap = *new* TreeMap<String, String>();
>
> *public* SortedMap<String, String> getPhoneNumberMap() {
>
> *return* phoneNumberMap;
>
> }
>
> *public* *void* setPhoneNumberMap(SortedMap<String, String> phoneNumberMap)
> {
>
> *this*.phoneNumberMap = phoneNumberMap;
>
> }
>
> *public* ImageCursorAdapter(Context context, *int* layout, Cursor c,
>
> String[] from, *int*[] to) {
>
> *super*(context, layout, c, from, to);
>
> *this*.c = c;
>
> *this*.context = context;
>
> }
>
>   *public* View getView(*int* pos, View inView, ViewGroup parent) {
>
> phoneNumberMap.put("1", "fasfa");
>
>   phoneNumberMap.put("2", "fasfa1");
>
> phoneNumberMap.put("3", "fasfa2");
>
> phoneNumberMap.put("4", "fasfa3");
>
> phoneNumberMap.put("5", "fasfa4");
>
> phoneNumberMap.put("6", "fasfa5");
>
> System.*out*.println(" Map : size: " + phoneNumberMap.size());
>
> }
> }// end of  class ImageCursorAdapter
>
> How can i access phoneNumberMap in the onListItemClick () method of
> Listcontacts class.

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

Reply via email to