0
我將列表視圖放置在項目單擊監聽器代碼供您參考。每個項目單擊列表視圖中我將用另一個片段替換片段.i將主片段(片段1)放入幀中佈局文件。我只是在相同的視圖中切換片段。片段內存管理
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) {
if(array[position].equalsIgnoreCase("movies")){
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment1, new next());
transaction.commit();
}
if(array[position].equalsIgnoreCase("serials")){
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment1, new Item2());
transaction.commit();
}
if(array[position].equalsIgnoreCase("restaurents")){
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment1, new Item3());
transaction.commit();
}
}
});
如果我點擊的片段1被新片段(第1項)同樣 更換電影,如果我在連續的片段1被新片段取代(第2項) 我想到點擊當我切換到新的片段(Item 1)時,片段1的內存將被釋放,並且當我點擊片段(Item 2)時,片段(Item 1)將被釋放,告訴我它將以相同的方式工作或不工作。因爲我需要爲每個列表項目單擊使用更多數量的片段(列表中的項目數量會更多)。我想知道它是否會以相同的方式發生,有沒有辦法管理片段的內存。建議我一個更好的方法來做到這一點,因爲我希望我的應用程序能夠運行內存泄漏。