Friday, 15 January 2010

android - Spinner values get doubled every time I click on the activity -


I'm using one piece activites in my activity is a spinner I set my adapter to this problem whenever I switch to that activity, spinner adds value. It actually adds the same value to the spinner without removing the previous one, how to solve it? My code is the following:

  increases the public class AddPackageFragment slice {see Routview; EditText packagename; Edit text package number; Spinner network; Checkbox sim1; Checkbox sim2; Radio group type; Radio group through; Add Button Package; Button job description; ArrayList & LT; String & gt; Network = New Arrestist & lt; String & gt; (); ArrayAdapter & LT; String & gt; Adapter; Reference Reference; @ Override Public View Crate View (LayoutInflator Inflator, View Group Container, Bundle Saved InstantState) {Routeview = Inflator.flat (R.Late.ad_package, container, falls); InitializeViews (); SetNetworks (); SetSpinner (); Return root view; } Zero initializeViews () {packageName = (EditText) rootView.findViewById (R.id.pName); PackageNumber = (edit text) rootView.findViewById (R.id.pNumber); Network = (Spinner) rootView.findViewById (R.id.networkS); Sim1 = (checkbox) rootView.findViewById (R.id.sim1); Sim2 = (checkbox) rootView.findViewById (R.id.sim2); Type = (radio group) Routview: FindVBIID (RID type group); Via = (radio group) RouteviewFindWebIID (Ridthrough Group); AddPackage = (button) rootView.findViewById (R.id.addPackage); ActDetails = (Button) rootView.findViewById (R.id.activationDetails); Context = getActivity (). GetApplicationContext (); AddPackage.setActivated (incorrect); ActDetails.setActivated (false); } Zero set networks () {networks.add ("Mobilink"); Networks.add ("telenor"); Networks.add ("Ufone"); Networks.add ("warid"); Networks.add ("Zong"); Network.add ("Add new"); } Zero set spinner () {adapter = new array adapter & lt; String & gt; (References, R.Lit.spinner_item, network); Network.setAdapter (zero); Network.setAdapter (adapter); }}    

to extend @demerge

piece Life cycle, if your onCreateView is said for more than one time, then you have to take into consideration and clear values ​​(or lists) accordingly.

piece life cycle

No comments:

Post a Comment