android - Creating a custom dialog box that displays a full view image -


i trying create custom dialog box displays image in full-view , has select cancel button. custom dialog box should displayed when image clicked allow user view selected image in full-view. image view should 1 selected gridview. select button display toast message , cancel button allow user exit dialog. idea allow user see image in full-view before or makes final choice on picture like.

however, having several problems trying this. code shown below:

  package com.newapp;    import android.app.activity;  import android.app.dialog;  import android.content.dialoginterface;  import android.content.context;  import android.os.bundle;  import android.view.view;  import android.widget.adapterview;  import android.widget.baseadapter;  import android.widget.gridview;  import android.widget.imageview;  import android.widget.toast;  import android.widget.adapterview.onitemclicklistener;  import android.widget.imageview;  import android.widget.button;  public class mainactivity extends activity { /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);  //error here: r cannot resolved variable          gridview gridview = (gridview) findviewbyid(r.id.photogrid);         gridview.setadapter(new imageadapter(this));          gridview.setonitemclicklistener(new onitemclicklistener() {             public void onitemclick(adapterview<?> parent, view v, int position, long id) {                 //toast.maketext(mainactivity.this, "" + position, toast.length_short).show();                 context mcontext = getapplicationcontext();                 dialog dialog = new dialog(mcontext);                  dialog.setcontentview(r.layout.imagedialog);                 dialog.settitle("full-image view");                  imageview image = (imageview) dialog.findviewbyid(r.id.image);                 image.setimageresource(r.drawable.android);                  button select = (button) findviewbyid(r.id.selectimage);                         buttonchangeperferences.setonclicklistener(new onclicklistener() {                             public void onclick(view v) {                              toast.maketext(mainactivity.this, "" + position, toast.length_short).show();                               }                         });                     }                      button cancel = (button) findviewbyid(r.id.cancelselection);                         cancel.setonclicklistener(new onclicklistener()     //error here: syntax error on tokens;annotationname expected instead                                         {                             public void onclick(view v) {                               dialog.cancel();                              }                         });          })                     }              package com.newapp;          import android.content.context;        import android.view.view;        import android.view.viewgroup;        import android.widget.baseadapter;        import android.widget.gridview;        import android.widget.imageview;     public class imageadapter extends baseadapter{  private context mcontext;  public imageadapter(context c) {     mcontext = c; }  public int getcount() {     return mthumbids.length; }  public object getitem(int position) {     return null; }  public long getitemid(int position) {     return 0; }  // create new imageview each item referenced adapter public view getview(int position, view convertview, viewgroup parent) {     imageview imageview;     if (convertview == null) {  // if it's not recycled, initialize attributes         imageview = new imageview(mcontext);         imageview.setlayoutparams(new gridview.layoutparams(85, 85));         imageview.setscaletype(imageview.scaletype.center_crop);         imageview.setpadding(8, 8, 8, 8);     } else {         imageview = (imageview) convertview;     }      imageview.setimageresource(mthumbids[position]);     return imageview; }  // references our images private integer[] mthumbids = {          r.drawable.sample_2, r.drawable.sample_3,         r.drawable.sample_4, r.drawable.sample_5,         r.drawable.sample_6, r.drawable.sample_7,         r.drawable.sample_0, r.drawable.sample_1,         r.drawable.sample_2, r.drawable.sample_3,         r.drawable.sample_4, r.drawable.sample_5,         r.drawable.sample_6, r.drawable.sample_7,         r.drawable.sample_0, r.drawable.sample_1,         r.drawable.sample_2, r.drawable.sample_3,         r.drawable.sample_4, r.drawable.sample_5,         r.drawable.sample_6, r.drawable.sample_7,         r.drawable.sample_0, r.drawable.sample_1,         r.drawable.sample_2, r.drawable.sample_3,         r.drawable.sample_4, r.drawable.sample_5,         r.drawable.sample_6, r.drawable.sample_7,  }; } 

can me fix these problems? appreciated.

i think need change line

button select = (button) findviewbyid(r.id.selectimage);

into

button select = (button) dialog.findviewbyid(r.id.selectimage);

and same cancel.

after select button used "buttonchangeperferences" instead of "select"...

you have problem r.layout because using r.layout.imagedialog name of layout in capital letters while should in lower case...

you need add dialog.show(); after declare buttons

plus, because complier has got confused may need rewrite lines , @ point when application still has little red mark in package explorer on right in exclipse, need go project menu clean , select application , click ok.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -