my intention in writing question i've fragment , i've loaded listview data , went fragment, when come fragment listview not loaded, means again fresh start.
another problem: i've fragment, i've instantiated , there view(say linear layout) in it, i've added 2 children it. i've loaded fragment , came back. again same problem. fragment started again no children .... please help
code second problem named problem:
fragment.class
package view; import android.app.activity; import android.app.alertdialog; import android.app.fragment; import android.content.context; import android.content.dialoginterface; import android.os.bundle; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.imageview; import android.widget.linearlayout; import android.widget.listview; import android.widget.toast; import java.util.arraylist; import adapters.playlistloadingadapterforspeakers; import amitechnologies.products.multizoneplayer.r; import interfaces.messagefrommainactivitytofrgmentmultizone; import interfaces.messagefromspeakerdetectortofragmentmultizoning; import model.globals; import model.playlistmodelsaved; import utilities.speakerinfo; import utilities.track; /** * created admin on 5/6/2015. */ public class fragment extends fragment { imageview loadplaylists; playlistmodelsaved playlistmodelsaved = playlistmodelsaved.getinstance(); playlistloadingadapterforspeakers adapterforspeakers; arraylist<track> playlistcontents = new arraylist<track>(); listview trackslistviewforspeakers; linearlayout parentofdockedplayers; arraylist<string> myzonenames; arraylist<string> myipaddress; @override public void onattach(activity activity) { super.onattach(activity); } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.fragment_multi_zoning, container, false); loadplaylists = (imageview) view.findviewbyid(r.id.loadplaylist); parentofdockedplayers = (linearlayout) view.findviewbyid(r.id.parentofmediaplayer); getzonesandips(); addzones(); trackslistviewforspeakers = (listview) view.findviewbyid(r.id.loadedplaylist); adapterforspeakers = new playlistloadingadapterforspeakers(getactivity(), r.layout.row_playlistcontent, playlistcontents); trackslistviewforspeakers.setadapter(adapterforspeakers); loadplaylists.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { string[] playlists = new string[playlistmodelsaved.getplaylists().size()]; playlists = playlistmodelsaved.getplaylists().toarray(playlists); if (playlists.length > 0) { alertdialog.builder selectplaylist = new alertdialog.builder(getactivity()); selectplaylist.settitle("select playlists"); selectplaylist.setitems(playlists, new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int playlist) { trackslistviewforspeakers.setvisibility(view.visible); loadplaylists.setvisibility(view.gone); loadplayistcontents(playlist); // savetoplaylist(playlist, audioadapter.albumsstateslist); } }); selectplaylist.create().show(); } else { toast.maketext(getactivity(), "there no playlists...", toast.length_short).show(); // addplaylist(); } } }); return view; } public void getzonesandips(){ myzonenames = new arraylist<string>(); for(string value:globals.zonemappingtable.values()){ myzonenames.add(value); } myipaddress= new arraylist<string>(); for(string key:globals.zonemappingtable.keyset()){ myipaddress.add(key); } } private void addzones() { int count = parentofdockedplayers.getchildcount(); int k; if(count>=0){ k= count; }else{ k=0; } int = globals.zonemappingtable.size(); if(i<=0){ toast.maketext(getactivity(),"there no wifi speakers detected",toast.length_short).show(); } else{ for(int j=0;j<i;j++){ singlezoneplayerview singlezoneplayerview = new singlezoneplayerview(getactivity()); singlezoneplayerview.setspeakername(myzonenames.get(j)); singlezoneplayerview.setspeakerip(myipaddress.get(j)); // singlezoneplayerview.setmessagefromsinglezoneplayerviewtomainactivity(mainactivity); singlezoneplayerview.setposition(k); parentofdockedplayers.addview(singlezoneplayerview); } } } // @override public void allavailablespeakersdetected(arraylist<speakerinfo> availablespeakers) { int count = parentofdockedplayers.getchildcount(); int j; if(count>=0){ j= count; }else{ j=0; } int size = availablespeakers.size(); if (size <= 0) { gettoast("there no wifi speakers detected"); } else { (int = 0; < size; i++,j++) { singlezoneplayerview singlezoneplayerview = new singlezoneplayerview(getactivity()); singlezoneplayerview.setspeakername(availablespeakers.get(i).getspeakername()); singlezoneplayerview.setspeakerip(availablespeakers.get(i).getspeakerip()); singlezoneplayerview.setposition(j); parentofdockedplayers.addview(singlezoneplayerview); } } } private void loadplayistcontents ( int playlist){ arraylist<string> playlisttitles = playlistmodelsaved.getplaylists(); string filename = playlisttitles.get(playlist); if (playlistcontents.size() > 0) playlistcontents.clear(); playlistcontents.addall(playlistmodelsaved.getsavedplaylistscontent(filename)); if (playlistcontents.size() == 0) { toast.maketext(getactivity(), "empty playlist", toast.length_short).show(); trackslistviewforspeakers.setvisibility(view.gone); loadplaylists.setvisibility(view.visible); } adapterforspeakers.notifydatasetchanged(); } public void gettoast(string a){ toast.maketext(getactivity(),a,toast.length_short).show(); } // @override public void senddata(arraylist<speakerinfo> availablespeakers,context context) { /* int count=-1; if(parentofdockedplayers!=null){ count = parentofdockedplayers.getchildcount(); }*/ int j=0; /*if(count>=0){ j= count; }else{ j=0; }*/ int size = availablespeakers.size(); if (size <= 0) { gettoast("there no wifi speakers detected"); } else { (int = 0; < size; i++,j++) { singlezoneplayerview singlezoneplayerview = new singlezoneplayerview(context); singlezoneplayerview.setspeakername(availablespeakers.get(i).getspeakername()); singlezoneplayerview.setspeakerip(availablespeakers.get(i).getspeakerip()); singlezoneplayerview.setposition(j); parentofdockedplayers.addview(singlezoneplayerview); } } } }
do in oncreateview:
@override public view oncreateview(layoutinflater inflater, viewgroup view, bundle savedinstancestate) { if (view != null) { viewgroup parent = (viewgroup) view.getparent(); if (parent != null) parent.removeview(view); } try { view rootview = inflater.inflate(r.layout.your_view, container, false); return rootview; } catch (inflateexception e) { /* view there, return view */ return view; } }
Comments
Post a Comment