android - Displaying pictures in a gridview -
hi i'm trying display images using gridview. i'm getting error when import android.widget.adapterview.onitemclicklistener says main cannot resolved or not field. code below:
import import android.app.activity; import android.os.bundle; import android.view.view; import android.widget.adapterview; import android.widget.gridview; import android.widget.toast; import android.widget.adapterview.onitemclicklistener; //error here: main cannot resolved or not field public class mainactivity extends activity { /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); 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(); } }); } } 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_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 tell me why getting error? appreciated. thanks
that unrelated import, i'd guess complaining this: r.layout.main
. layout defined? need import correct r file, 1 generated in package: com.newapp.r?
also, assume import @ beginning copy error?
Comments
Post a Comment