android layout - I've got an auto-generated list that's not accepting the onclick method -


i've got auto-generated list

 <listview     android:id="@android:id/list"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:textisselectable="true"     android:longclickable="true"         android:onclick="onclick"       /> 

and debugger fails on grabbing "android:onclick" method,

i'm trying specific item that's "long-clicked" , delete it, have delete working, , know need

position = lv.getpositionforview(view); (object) getlistadapter().getitem(position); 

but i'm not sure how make listener , attach code this. ideas?

i've got in oncreate method:

final listview lv = (listview) findviewbyid(android.r.id.list);      lv.setonlongclicklistener( new view.onlongclicklistener() {          @ override          public boolean onlongclick(view v) {             int position = lv.getpositionforview(v);             log.d(tag, "position in here: " + position);             if (getlistadapter().getcount() > 0) {                 encouragement encouragement = (encouragement) getlistadapter().getitem(position);                 datasource.deleteencouragement(encouragement);                 adapter.remove(encouragement);                 adapter.notifydatasetchanged();             }              return false;         }      }); 

but it's not reaching log.d(tag, "position in here: " + position);

used code work out solution

import android.widget.adapterview.onitemlongclicklistener;  lv.setonitemlongclicklistener(new onitemlongclicklistener() {  public boolean onitemlongclick(adapterview<?> arg0, view arg1, int arg2,             long arg3) {         log.d(tag, "clicked on item "+arg1);         return false; } }); 

the problem wasn't selecting specific item list, general item confusing compiler.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -