2011-03-14 26 views

回答

0

擁有'許多'列表並使它們變爲靜態並不是非常有效。您可以使用我認爲更高效的內容提供者。

1

擴展應用程序並讓它保存您的數據。然後在你的意圖你

((MyApplication)getApplication()).getData(); 
1

避免使static變量。它快速而無痛,但真正快速變得凌亂。

入住這早些時候question

2

我不認爲一個靜態字段是你想要的這裏。你沒有提到這個xml來自哪裏,但我假設你的意思是一個在你的應用程序中包含的xml文件中指定的字符串數組。在這種情況下,您需要獲取Resources對象的句柄,爲此您需要一個Context。

應用程序對象始終圍繞並可從您的所有活動訪問。我會在這裏創建並存儲這些全局ArrayLists。因爲它聽起來像你有一堆,所以你可以在你的Application類中有一個MapLayer和一個函數,它取得你想要的ArrayList的名字,並從Map中返回適當的ArrayList。

public class MyApp extends Application { 

private Map<String, ArrayList<String>> mLists=new HashMap<String, ArrayList<String>>(); 


public void addList(String key, ArrayList<String> list) { 
     mLists.put(key,list); 

} 

public ArrayList<String> getList(String key) { 

    return mLists.get(key); 

} 

} 
相關問題