Saturday, 15 June 2013

android - ListView add items two times in onCreate -


In my Master Details flow I call this function to make my list:

 < Code> public class enhances the Ansicht SherlockFragmentActivity {@Override protected void onCreate (Bundle Saved InstantState)) {// ... ListItems.setupMainItems (this); // ...}} public class lists {public static list & lt; DetailListItem & gt; Item = new arreelist & lt; Extension Lists & gt; (); Public static map & lt; String, extension list and gt; ITEM_MAP = new hashmap & lt; String, extension list and gt; (); Public Static Zero AddItem (String Value, Type T) {DetailListItem Item = New DetailListItem (Value, T); ITEMS.add (item); ITEM_MAP.put (item.id, item); } // ...} Public Category ListControl enhances SherlockListFragment {@Override Creatives (bundled saved instainstate) {super.onCreate (SavedInstanceState) on Public Zero; Adapter = new array adapter & lt; ListItems.DetailListItem & gt; (GetSherlockActivity (), R.Lay Out.Simple_listitem, android.R.id.text1, ListItems.ITEMS); SetListAdapter (adapter); } // ...}   

But if I close my app and start again, the items are inserted for a second time. I think I do not need to call this function on Crete but it really does not help me because the first method on the creator is called.

In my setupMainItems method I only call AddItem method onPause and onResume are not overridden if I have my app If I close it with the Home button then it works well, but if I close it with the back button then insert the item a second time.

"text">

you can do something like

  if (ListItems.ITEMS == zero || ListItems.ITEMS.size () == 0) ListItems.setupMainItems (This);   

In this way, it will only add items if they have not already been added

No comments:

Post a Comment