java - How to get path of checked picture using checkbox from grid view of photo Gallery in android -


i trying path of photo gallery in grid view. gallery consists of each thumbnail attached checkbox. here whole code:

    public class gridgallery extends activity {      arraylist<string>list; alertdialog.builder alert; private button send; gridview gridview; @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.grid_gallery);     datamodel dbmodel = new datamodel(this);     list = dbmodel.selectall();                     alert = new alertdialog.builder(gridgallery.this);     send = (button)findviewbyid(r.id.send_message);     gridview = (gridview) findviewbyid(r.id.sdcard);     gridview.setadapter(new imageadapter(this));              gridview.setclickable(true);             gridview.setonitemclicklistener(new onitemclicklistener() {          public void onitemclick(adapterview<?> arg0, view view, int pos,                 long id)          {             // todo auto-generated method stub             final int position = pos;             final string path = list.get(position).tostring();             final string option[] = new string[]{"send to","watch"};             alert.settitle("pick options");             alert.setitems(option, new  onclicklistener() {                  public void onclick(dialoginterface dialog, int which)                  {                     // todo auto-generated method stub                     if(option[which].equals("watch"))                     {                         if(path.contains(".jpg"))                         {                             intent intent = new intent(intent.action_view);                                     intent.setdataandtype(uri.fromfile(new file(list.get(position))), "image/jpeg");                             startactivity(intent);                                           }                         else if(path.contains(".mp4"))                         {                             intent intent = new intent(intent.action_view);                                     intent.setdataandtype(uri.fromfile(new file(list.get(position))), "video/*");                             startactivity(intent);                         }                         else                         {                             intent intent = new intent(intent.action_view);                                     intent.setdataandtype(uri.fromfile(new file(list.get(position))), "audio/*");                             startactivity(intent);                         }                     }//                     else                     {                         intent sendmail = new intent(gridgallery.this, sendmessage.class);                         sendmail.putextra("path", path);                         startactivity(sendmail);                                                 }                 }             }).show();         }     });     send.setonclicklistener(new view.onclicklistener() {          public void onclick(view v)          {             // todo auto-generated method stub             string path = null;                           intent sendtomail = new intent(gridgallery.this, sendmessage.class);             sendtomail.putextra("path", path);             startactivity(sendtomail);          }     }); }    /**  * adapter our image files.  */ private class imageadapter extends baseadapter  {      private final context context;      bitmap bitmap;      public imageadapter(context localcontext) {         context = localcontext;     }      public int getcount()      {         return list.size();     }     public object getitem(int position)      {         return position;     }     public long getitemid(int position)      {         return position;     }      public view getview(int position, view convertview, viewgroup parent)      {         imageview picturesview;         view myview = convertview;          if (convertview == null)          {              layoutinflater layoutinflater = (layoutinflater)context.getsystemservice(context.layout_inflater_service);//getlayoutinflater();             myview = layoutinflater.inflate(r.layout.image_selection, null);              picturesview = new imageview(context);             picturesview = (imageview)myview.findviewbyid(r.id.item_grid);             picturesview.setclickable(true);              if(list.get(position).contains(".jpg"))             {                  bitmap = bitmapfactory.decodefile(list.get(position));              }             else if(list.get(position).contains(".mp4"))             {                 bitmap = thumbnailutils.createvideothumbnail(list.get(position), 0);              }             else             {              }              picturesview.setimagebitmap(bitmap);             picturesview.setscaletype(imageview.scaletype.fit_center);             picturesview.setpadding(8, 8, 8, 8);             return myview;         }         else          {             myview = convertview;             return myview;         }      } } 

}

my problem can not able click image or video thumbnail. how able image when checked check box.

here xml code image_selection:-

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"            android:layout_height="fill_parent" android:orientation="vertical" android:gravity="center_horizontal">          <imageview  android:id="@+id/item_grid" android:layout_width="100dip" android:layout_height="100dip"/>          <checkbox android:id="@+id/check" android:layout_width="wrap_content" android:layout_height="wrap_content" /> 

and grid_gallery.xml:-

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <gridview xmlns:android="http://schemas.android.com/apk/res/android"      android:id="@+id/sdcard"     android:layout_width="fill_parent"      android:layout_height="fill_parent"     android:padding="10dp"     android:verticalspacing="10dp"     android:horizontalspacing="10dp"     android:numcolumns="auto_fit"     android:columnwidth="90dp"     android:stretchmode="columnwidth"     android:gravity="center" /> </relativelayout> 

please me. in advance

it seems store image path in arraylist list. if so, set onitemclicklisteber gridview. in onitemclick method position of gridview clicked. try 'list.get(position)in theonitemclick` path


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -