android - Progress bar while start activity -


in code want use ring progressdialog open , loading each activity.

my code not work well. in code, progressbar closed , activity open after long time.

i want add progressdialog in onlistitemclick, plz me

public class listsoti extends listactivity {  string[] str = {"1","2","3","4","5","6","7","8","9","10","11","12","13","14"}; @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.listview);      textview list = (textview) findviewbyid(r.id.hamid);     persianreshape.reshapetextview(list, "hamid1.ttf", listsoti.this);     setlistadapter(new myadapter(this,             android.r.layout.simple_list_item_1,r.id.textview1, str)); }  private class myadapter extends arrayadapter<string>{      public myadapter(context context, int resource, int textviewresourceid,             string[] strings) {         super(context, resource, textviewresourceid, strings);     }      @override     public view getview(int position, view convertview, viewgroup parent) {         layoutinflater inflater = (layoutinflater) getsystemservice(context.layout_inflater_service);         view row = inflater.inflate(r.layout.listsoti, parent, false);         string[] items = getresources().getstringarray(r.array.contor);          imageview iv = (imageview) row.findviewbyid(r.id.imageview1);         textview tv = (textview) row.findviewbyid(r.id.textview1);         persianreshape.reshapetextview(tv,"hamid1.ttf", listsoti.this);         tv.settext(items[position]);          switch (position) {         case 0:            iv.setimageresource(r.drawable.dozdeh);            break;         case 1:             iv.setimageresource(r.drawable.download);             break;         default:             break;         }         return row;     } } @override protected void onlistitemclick(listview l, view v, int position, long id) {     toast.maketext(this, str[position] +" choose", toast.length_long).show();     switch (position) {     case 0:         startactivity(new intent(listsoti.this, play.class));          break;     case 1:         final dialog dialog = new dialog(this);          dialog.requestwindowfeature(window.feature_no_title);          dialog.setcontentview(r.layout.progressdialog);         dialog.show();         startactivity(new intent(listsoti.this, play.class));           break;     default:         break;         } } 

edit, loading class

public class loadingscreenactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); system.out.println("loadingscreenactivity  screen started"); setcontentview(r.layout.loading_screen); spinner s = (spinner) findviewbyid(r.id.mainspinner1); s.setvisibility(view.visible); //do work if needed , launch new activity intent mainintent = new intent(loadingscreenactivity.this,play.class);      loadingscreenactivity.this.startactivity(mainintent);      loadingscreenactivity.this.finish();  } 

}

you can use example, loadingactivity, create every time need show progressdialog'. can customize passing activity name throughintentwhich gonna launched next. able reuse thisactivity` many times. check it, please.

  1. create loadingscreen layout file

here create screen shows loading text , progress bar loading_screen.xml

<linearlayout   xmlns:android="http://schemas.android.com/apk/res/android"   android:layout_width="fill_parent"    android:gravity="center" android:orientation="vertical"   android:layout_height="fill_parent" android:background="#e5e5e5">     <textview android:text="please wait while data gets loaded..."         android:layout_width="wrap_content" android:layout_height="wrap_content"         android:textcolor="#000000">    </textview>   <progressbar android:id="@+id/mainspinner1" android:layout_gravity="center"              android:layout_width="wrap_content" android:layout_height="wrap_content"             android:indeterminate="true"              style="?android:attr/progressbarstyleinverse">    </progressbar>  </linearlayout> 
  1. create loadingscreen class file

and in loadingscreenactivity.class override oncreate usually:

@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); system.out.println("loadingscreenactivity  screen started"); setcontentview(r.layout.loading_screen); spinner s = findviewbyid(r.id.mainspinner1); s.setvisibility(view.visible); //do work if needed , launch new activity intent mainintent = new intent(loadingscreenactivity.this,profiledata.class);      loadingscreenactivity.this.startactivity(mainintent);      loadingscreenactivity.this.finish();  } 

this load next activity once custom task finished. 3. open loadingscreenactivity list onlistitemclick event

create intent launch loading screen activity

protected void onlistitemclick(listview l, view v, int position, long id) {         super.onlistitemclick(l, v, position, id);  intent intent = new intent(profilelist.this, loadingscreenactivity.class);         startactivity(intent); } 

update

for case launch loadingactivity clicking button should add code current activity:

yourbutton.setonclicklistener(new onclicklistener(){    @override    public void onclick(view view){       intent intent = new intent(this, loadingscreenactivity.class);             startactivity(intent);    } } 

edit

this code place in play.class in method oncreate()

    dialog dialog = new dialog(this);      dialog.requestwindowfeature(window.feature_no_title);      dialog.setcontentview(r.layout.progressdialog);     dialog.show(); 

then initialize loading file , when loading done, call method dialog.dismiss(); , continue working.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -