Hi, I have solved the re adding by clearing the list items first - see code below. For the fragment that i want to add i have added the following image - on each sliding tab i have a different list view. When i click an item on the list view i want to show a different fragment that has in it some controls (all fragments will have a Start/Stop button in common). Next step will be to have the first item in each list selected when the tab is changed so that i will have the associated fragment shown .
<https://lh3.googleusercontent.com/-TbJuaLJ9LRA/VcoFFMxCUzI/AAAAAAAAIio/A_dIWX5vRPU/s1600/TabletInterface.png> public class Tab_Modes extends ListFragment { private ArrayList<NameImg> items = new ArrayList<NameImg>(); private int crtMode; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = super.onCreateView(inflater, container, savedInstanceState); Bundle arguments = getArguments(); crtMode = arguments.getInt("position"); Toast.makeText(getActivity(), "Crt Frag :" + arguments.getString("frag"), Toast.LENGTH_LONG).show(); items.clear() switch (crtMode) { case 0: items.add(new NameImg("Manual", "Simple camera Control", R. drawable.hand)); items.add(new NameImg("Bulb", "Long Exposure", R.drawable.bulb )); items.add(new NameImg("Time Lapse", "Frame by Frame Movie", R. drawable.timelapse)); items.add(new NameImg("HDR", "High Dinamic Range", R.drawable. hdr)); items.add(new NameImg("IR", "Infra RED Control", R.drawable.ir )); break; case 1: items.add(new NameImg("Triggered", "Trigger camera ", R.drawable .triggrered)); items.add(new NameImg("Dark Room", "Long Exposure", R.drawable. darkroom)); items.add(new NameImg("Lightning", "Frame by Frame Movie", R. drawable.lightning)); break; case 3: items.add(new NameImg("1", "USB1", R.drawable.usb)); items.add(new NameImg("2", "USB2", R.drawable.waterdrops)); break; } setListAdapter(new ModesItemAdapter(getActivity(), items)); //ListView myLV = null; //myLV = (ListView) myLV.findViewById(R.id.customListView); //myLV.setItemChecked(0, true); return v; } On Tuesday, August 11, 2015 at 4:25:27 AM UTC+2, TreKing wrote: > > > On Wed, Jul 29, 2015 at 1:51 AM, gvi70000 <[email protected] <javascript:> > > wrote: > >> In my application i have a SlidingTabLayout, each tab containing a >> listview. when i go through the tabs several times the items are added in >> the listview each time. how can i prevent this behaviour? >> > > Step through your code and debug the problem. Put a breakpoint where the > items are being added and review the stacktrace that leads to the multiple > calls. My guess would be the fact that you have an "items" array allocated > at Fragment construction time and add stuff to it in onCreateView, which > can get called multiple times within the fragment's lifecycle. > > the second question >> >> On each tab i want to add a second fragment that will hold some controls, >> each fragment has to be linked with a list item from the list view, when i >> switch the tab the first list item has to be selected to display the >> corresponding fragment. How can i achieve this behavior? >> > > You need to provide pictures or something. Your description is hard to > follow and thus impossible to answer. > > > ------------------------------------------------------------------------------------------------- > TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago > transit tracking app for Android-powered devices > -- 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 --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

