multithreading - Load All Phone Images to GridView with Thread in Android -


i have problem thread in android . have gridview checkbox , want load images gallery grid . want load thread. when click load images program closed. code . please see , give me best solution . thanks

add_image.java :

public class add_images extends activity implements runnable {      private int count;     private bitmap[] thumbnails;     private boolean[] thumbnailsselection;     private string[] arrpath;     private imageadapter imageadapter;     private string selectimages="";     private final progressdialog pd = new progressdialog(this);      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.add_images);         pd.setprogressstyle(progressdialog.style_spinner);         pd.setmessage("please wait...");         pd.setindeterminate(false);         pd.setcancelable(true);         pd.show();         thread t = new thread(add_images.this);         t.start();     }      @override     public void run(){         getlist();     }      private void getlist() {         try {                 final string[] columns = { mediastore.images.media.data,                     mediastore.images.media._id };             final string orderby = mediastore.images.media._id;             cursor imagecursor = managedquery(                     mediastore.images.media.external_content_uri, columns,                     null, null, orderby);             final int image_column_index = imagecursor                     .getcolumnindex(mediastore.images.media._id);             this.count = imagecursor.getcount();             this.thumbnails = new bitmap[this.count];             this.arrpath = new string[this.count];             this.thumbnailsselection = new boolean[this.count];             (int = 0; < this.count; i++) {                 imagecursor.movetoposition(i);                 final   int id = imagecursor.getint(image_column_index);                 final   int datacolumnindex = imagecursor                         .getcolumnindex(mediastore.images.media.data);                 thumbnails[i] = mediastore.images.thumbnails.getthumbnail(                         getapplicationcontext().getcontentresolver(), id,                         mediastore.images.thumbnails.micro_kind, null);                 arrpath[i] = imagecursor.getstring(datacolumnindex);                 pd.setprogress(i);             }             gridview imagegrid = (gridview) findviewbyid(r.id.add_select_phoneimagegrid);             imageadapter = new imageadapter();             imagegrid.setadapter(imageadapter);             imagecursor.close();             pd.dismiss();          } catch (exception ex) {          }     } 

add_image.xml :

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent" >      <button         android:id="@+id/btn_images_back"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentbottom="true"         android:minwidth="110px"         android:text="back main" android:onclick="onclick" />     <button         android:id="@+id/btn_images_selected"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_alignparentbottom="true"         android:layout_torightof="@+id/btn_images_back"         android:text="select" android:onclick="onclick"/>      <gridview         android:id="@+id/add_select_phoneimagegrid"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:layout_above="@id/btn_images_selected"         android:columnwidth="90dp"         android:gravity="center"         android:horizontalspacing="10dp"         android:numcolumns="auto_fit"         android:stretchmode="columnwidth"         android:verticalspacing="10dp" />  </relativelayout> 

add_view_galleryitem.xml :

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent" >      <imageview         android:id="@+id/add_view_thumbimage"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centerinparent="true" />      <checkbox         android:id="@+id/add_view_itemcheckbox"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentright="true"         android:layout_alignparenttop="true" />  </relativelayout> 

something this

    pd.setprogressstyle(progressdialog.style_spinner);     pd.setmessage("please wait...");     pd.setindeterminate(false);     pd.setcancelable(true);     pd.show(); new thread(add_images.this) {                     @override                     public void run() {                            try {                                  // code runs in thread                                  activity.runonuithread(new runnable() {                                         @override                                         public void run() {                                                // code runs in ui(main) thread                                         }                                  });                            } catch (final exception ex) {                            }                     }              }.start(); 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -