android - How to write a onClick listener for a ListView? -


this arrayadapter:

public class listarrayadapter extends arrayadapter<string>  {       public arraylist<string> links = new arraylist<string>();     public activity activity = new activity();      textview linktext;      textview linkdesc;      public context c;     public listarrayadapter(context context, int textviewresourceid,             arraylist<string> fiokilist, object o) {          super(context, textviewresourceid, fiokilist);         this.links = fiokilist;         activity = (activity) (o);         c = context;         //notifydatasetchanged();      }       public view getview(final int position, view convertview, viewgroup parent) {         view v = convertview;          if (convertview == null) {             convertview = layoutinflater.from(getcontext()).inflate(                     r.layout.list_item, parent, false);                convertview.setonclicklistener(new onclicklistener() {                        @override                     public void onclick(view v) {                         // todo auto-generated method stub                          toast.maketext(activity, string.valueof(position), toast.length_long).show();                     }                 });          }            final string link = this.links.get(position);           linktext  = (textview) convertview.findviewbyid(r.id.linktitle0001);     //  linkimageview = (smartimageview) convertview.findviewbyid(r.id.faviconview0001);         linktext.settext(link);            //imageview imgview = (imageview)convertview.findviewbyid(r.id.imageview1);      //  piemenu piemenu = new piemenu(imgview, activity);         //fl.addview(piemenu);              return convertview;         }  } 

i understand how write onclicklistener entire item of listview? understand how write 1 each item, don't how view?

remove did inside adapter , add code inside main activity call adatper

setonitemclicklistener

is function should call.

list_view.setonitemclicklistener(new onitemclicklistener() {  @override   public void onitemclick(adapterview<?> arg0,view arg1, int position, long arg3) { // todo auto-generated method stub      } }); 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -