@ItemClick on GridView not detected - android annotation -


hi using android annotation in activity. not able detect click on gridview items. @itemclick(r.id.ordereditemslist) void itemclicked(int position){ log.w("cartactivity", "clicked detected"); }

myactivity

public class cartactivity extends actionbaractivity implements cartitemlistener {  private static final string log_tag = cartactivity.class.getname();  private list<cartorderitem> orderitems; private dialog confirmdialog;  @viewbyid(r.id.ordereditemslist) gridview cartitems;  @viewbyid(r.id.buyoptions) radiogroup buyoptions;  @viewbyid(r.id.clearcart) button clearbtn;  @viewbyid(r.id.placeorder) button buybtn;  @viewbyid(r.id.totalcost) textview totalcost;  @viewbyid(r.id.totalheading) textview totaltitle;  @viewbyid(r.id.paymentstatus) textview paystatus;  @bean fudzonerestclient restclient;  @bean fudzonepersistence persistence;  @extra long restaurantid;  @extra list<cartitems> cart;  private cartadapter adapter; private long userid; private static int attemptedremove = -1;  @afterviews void init(){     log.d(log_tag, "cart items got "+cart.tostring());      adapter = new cartadapter(this, cart);     adapter.setcartitemlistener(this);     cartitems.setadapter(adapter);      cartitems.setvisibility(view.visible);     paystatus.setvisibility(view.gone);      setbuystatus();      try {         int index = persistence.getenduserrepository().getall().size();         userid = persistence.getenduserrepository().get(index).getenduserid();      } catch (sqlexception e) {         log.e(log_tag, "could not fetch userid persistence");         e.printstacktrace();     } }  private void showremoveconfirmation() {     alertdialog.builder alertdialog = new alertdialog.builder(cartactivity.this);      alertdialog.settitle("confirm delete");     alertdialog.setmessage("are sure want remove item?");      alertdialog.setpositivebutton("yes", new dialoginterface.onclicklistener() {         public void onclick(dialoginterface dialog, int which) {             adapter.removefromcart(attemptedremove);             totalcost.settext(string.valueof(adapter.gettotalcost()));             if (adapter.getcount() == 0) {                 buybtn.setenabled(false);             }         }     });      alertdialog.setnegativebutton("no", new dialoginterface.onclicklistener() {         public void onclick(dialoginterface dialog, int which) {             dialog.cancel();         }     });     alertdialog.show(); } @itemclick(r.id.ordereditemslist)    void itemclicked(int position){    log.w("cartactivity", "clicked detected"); }  @click(r.id.clearcart) void clearcart(){     cart.clear();     adapter.clearall();     setbuystatus(); }  @click(r.id.placeorder) void placeorder(){      confirmdialog = new dialog(this);         confirmdialog.setcancelable(false);         confirmdialog.setcontentview(r.layout.dialog_order_confirmation);         button accept = (button) confirmdialog.findviewbyid(r.id.confirmaccept);         button cancel = (button) confirmdialog.findviewbyid(r.id.confirmcancel);      accept.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             sendorder();         }     });      cancel.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             confirmdialog.dismiss();         }     });      confirmdialog.show(); }  @background protected void sendorder() {     cartorders cartorders = new cartorders();     cartorders.setrestaurantid(restaurantid);     cartorders.setenduserid(userid);     switch (buyoptions.getcheckedradiobuttonid()) {         case r.id.takeaway:             cartorders.setdeliverytype(deliverytype.take_away);             cartorders.setdeliverylocationid(null);             break;         case r.id.delivery:             cartorders.setdeliverytype(deliverytype.home_delivery);             break;     }      orderitems = null;     orderitems = new arraylist<cartorderitem>();     double totalcst = 0;     for(cartitems item : cart){         cartorderitem temp = new cartorderitem();         temp.setproductid(item.getcartorder().getfoodid());         temp.setquantity(item.getcartorder().getquantity());         orderitems.add(temp);         totalcst += item.getcartorder().getprice() * item.getcartorder().getquantity();     }      cartorders.setcartorderitem(orderitems);     cartorders.settotalcost(totalcst);      gson gson = new gson();      /*retrofit code*/     restadapter restadapter = new restadapter.builder()             .setendpoint(connectionutil.baseurl)  //call base url             .build();      icartcontroller cartcontroller = restadapter.create(icartcontroller.class);     cartcontroller.sendorder(gson.tojson(cartorders), new callback<cartresponse>() {         @override         public void success(cartresponse cartresponse, response response) {             if (response.getreason().equals("ok")) {                 crouton.showtext(cartactivity.this, "order placed. order number " + cartresponse.getorderid(), style.confirm);                 clearcart();                 cartitems.setvisibility(view.gone);                 paystatus.setvisibility(view.visible);                 totaltitle.settext("order number : ");                 totalcost.settext(string.valueof(cartresponse.getorderid()));                 paystatus.settext("order processed after payment processed.");                 openpaymentoptions(cartresponse);             }         }          @override         public void failure(retrofiterror error) {             crouton.showtext(cartactivity.this, "order couldn't placed, please try after sometime.", style.confirm);             error.printstacktrace();         }     });      /*retrofit code end*/      log.d(log_tag, gson.tojson(cartorders));     confirmdialog.dismiss();  }  private void setbuystatus(){     if (cart.size() == 0) {         buybtn.setenabled(false);         clearbtn.setenabled(false);     }else {         buybtn.setenabled(true);         clearbtn.setenabled(true);     }     totalcost.settext(string.valueof(adapter.gettotalcost())); }  void openpaymentoptions(cartresponse cartresponse){     if (cartresponse != null) {         paymentpageactivity_.intent(cartactivity.this)                 .txurl(cartresponse.gettransactionurl())                 .startforresult(paymentpageactivity.payment_gateway);     } }  @override public void onbackpressed() {     if(cart.size() == 0) {         adapter = null;         super.onbackpressed();     }     crouton.showtext(this, "cart needs empty before can exit", style.info); }  @override public boolean oncreateoptionsmenu(menu menu) {     settitle("cart");     return true; }  @override public boolean onoptionsitemselected(menuitem item) {     switch (item.getitemid()) {         // respond action bar's up/home button         case android.r.id.home:             if(cart.size() == 0) {                 adapter = null;                 super.onoptionsitemselected(item);                 return true;             }      }     crouton.showtext(this, "cart needs empty before can exit", style.info);     return false; }  @override protected void onactivityresult(int requestcode, int resultcode, intent data) {      if(requestcode == paymentpageactivity.payment_gateway){         switch(resultcode){             case -1:                 crouton.showtext(cartactivity.this, "error processing payment : aborted", style.alert);                 break;             case -2:                 crouton.showtext(cartactivity.this, "error processing payment : failed payment", style.alert);                 break;             case -3:                 crouton.showtext(cartactivity.this, "error processing payment : user termination", style.alert);                 break;             default:                 totalcost.settext("");                 updatepaymentinbackend(data);         }     } }  @background void updatepaymentinbackend(final intent data){     if(data != null) {         if(restclient.getordercontroller().updatepayment(data.getstringextra("txno"))){              updatepaymentinfo(true, data.getstringextra("orderid"),                     data.getstringextra("bankref"),                     data.getstringextra("txno"));         }else{             updatepaymentinfo(false, "", "", "");         }     }else{         updatepaymentinfo(false, "", "", "");     } }  @uithread  void updatepaymentinfo(boolean done, string orderid, string bankref, string txno) {     if(done) {         crouton.showtext(cartactivity.this, "payment successful.", style.confirm);         cartitems.setvisibility(view.gone);         paystatus.setvisibility(view.visible);         totaltitle.settext("please note these details reference.");          paystatus.settext("\norder number : " + orderid +                 "\nbank ref number : " + bankref +                 "\ntransaction number : " + txno);      }else{         totaltitle.settext("payment processing has failed, contact support or retry myorders");         /*todo : add retry button , call dopayment*/     } }  @override public void removeitemlistener(int pos) {     attemptedremove = pos;     showremoveconfirmation(); } 

}

adapter

public class cartadapter extends baseadapter {  private static final string log_tag = cartadapter.class.getname(); private list<cartitems> cartitems; private layoutinflater inflater; private context context; private imageloaderservice_ imageloaderservice; private double totalcost; cartitemlistener itemlistener;  public cartadapter(context context, list<cartitems> cartitems) {     this.cartitems = cartitems;     this.context = context;     inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service);     imageloaderservice = imageloaderservice_.getinstance_(context); }  public void setcartitemlistener(cartitemlistener itemlistener){     this.itemlistener = itemlistener; }  @override public int getcount() {     return cartitems.size(); }  @override public object getitem(int position) {     return cartitems.get(position); }  @override public long getitemid(int position) { //todo :i think better disable click on cart items.     try {         return cartitems.get(position).getfoodid();     }catch (nullpointerexception e) {         log.e(log_tag, "something when wrong , get(position) returned null, returning 0 avoid crash");         e.printstacktrace();         return 0;     } }  @override public view getview(final int position, view convertview, viewgroup parent) {     if(convertview == null){         convertview = inflater.inflate(r.layout.hotel_menu_item, null);     }      imageview menuimg = (imageview) convertview.findviewbyid(r.id.menuimg);     imageview menutypeimg = (imageview) convertview.findviewbyid(r.id.foodtypeimg);     textview incart = (textview) convertview.findviewbyid(r.id.noofitems);     textview menuitemname = (textview) convertview.findviewbyid(r.id.menuitemname);     textview menuitemcost = (textview) convertview.findviewbyid(r.id.menuitemcost);     linearlayout btnholder = (linearlayout) convertview.findviewbyid(r.id.buttonholder);      btnholder.setvisibility(view.gone);      imageloaderservice.getloader().displayimage(connectionutil.baseurl+"/"+cartitems.get(position).getphoto(), menuimg);      switch(cartitems.get(position).getfoodtype()){         case vegetarian:             menutypeimg.setimagedrawable(context.getresources().getdrawable(r.drawable.veg));             menutypeimg.setcontentdescription("contains veg.");             break;         case non_vegetarian:             menutypeimg.setimagedrawable(context.getresources().getdrawable(r.drawable.non_veg));             menutypeimg.setcontentdescription("contains non-veg.");             break;         case contains_egg:             menutypeimg.setimagedrawable(context.getresources().getdrawable(r.drawable.egg));             menutypeimg.setcontentdescription("contains egg.");             break;     }      incart.settext(cartitems.get(position).getcartorder().getquantity().tostring());     menuitemname.settext(cartitems.get(position).getcartorder().getfoodname());     menuitemcost.settext(cartitems.get(position).getcartorder().getprice().tostring());      /*convertview.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view view) {             itemlistener.removeitemlistener(position);         }     });*/      return convertview; } } 

the click not @ detected.i tried @itemlongclick, @itemselect no click events detected. have suggestions.

thanks

hello first of there 3 suggestions :-

1.)annotated activity eactivity or eactivity(r.layout.activity_layout_cartactivity)

2.)register activity manifest.xml cartactivity_ instead of cartactivity

3.) check build.gradle file androidannotations available instead of pure roboguice gradle gile like...

app.gradle:-

apply plugin: 'com.neenbedankt.android-apt' def aaversion = '3.3.2' // change desired version, example latest stable: 3.3.2 

.......

apt {     arguments {         androidmanifestfile variant.outputs[0].processresources.manifestfile         // if have multiple outputs (when using splits), may want have other index 0          // should set package name here if using different application ids         // resourcepackagename "your.package.name"          // can set optional annotation processing options here, these commented options:         // loglevel 'info'         // logfile '/var/log/aa.log'     } } 

......

dependencies {   apt "org.androidannotations:androidannotations:$aaversion" compile "org.androidannotations:androidannotations-api:$aaversion"} 

-------- thats .

thanks hope helps


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -