java - Object methods in android extended array adapter -


i having following object in activity class:

/**  * item object  */ class orderitem {     /**      * private params      */     private string item_name;     private double item_price;     private integer quantity;      public void orderitem(string name, double price, integer qt){         /**          * init object properties          */         this.item_name = name;         this.item_price = price;         this.quantity = qt;     }     /**      * getters , setters      */     public string getname(){         return this.item_name;     }     public void setname(string name){         this.item_name = name;     }      public double getprice(){         return this.item_price;     }     public void setprice(double price){         this.item_price = price;     }      public integer getquantity(){         return this.quantity;     }     public void setquantity(integer qt){         this.quantity = qt;     } } 

and using object update listview item. i've set custom adapter list, handle current object, , add data given view. here code of adapter:

class orderobjectadapter<orderitem> extends arrayadapter<orderitem>{     private final context context;     private final list<orderitem> object;      public orderobjectadapter(context context,list<orderitem> object){         super(context, r.layout.order_object_layout, object);         this.context = context;         this.object = object;     }      @override     public view getview(int position, view conertview, viewgroup parent){         layoutinflater inflater = (layoutinflater)                 context.getsystemservice(context.layout_inflater_service);         view rowview = inflater.inflate(r.layout.order_object_layout, parent, false);         /** gather items view */         textview p_name = (textview) rowview.findviewbyid(r.id.product_name);         textview p_value = (textview) rowview.findviewbyid(r.id.product_value);         textview p_quantity = (textview) rowview.findviewbyid(r.id.product_quantity);         /** asign data text views */         orderitem item = (orderitem) object.get(position);         p_name.settext("");         return rowview;     } } 

and how use it:

    /**      * init order_items adapter      */     order_details_list_view = (listview)findviewbyid(r.id.order_details_list_view);     order_items = new arraylist<orderitem>();     order_items_adapter = new orderobjectadapter(            this,order_items     );     /** set list adapter order items */     order_details_list_view.setadapter(order_items_adapter); 

my problem in method getview of custom adapter, if want assign object data view, object property adapter, returning me out object pointer(i think) instead of object on wich can call getter methods data. here sample of returned if put log.e on it:

e/item﹕ com.avicolaarmeli.armeli.orderitem@41561f98 

even if typecast orderitem or create new var like: orderitem item = object.get(position); still cannot access object's methods.

i've been trying sort out day , couldn't understand why. can please let me know what's wrong code?

thanks

what seeing this.tostring(), default implementation of object.tostring(), since not overriding it.

add

@override public string tostring() {    return this.item_name != null ? this.item_name : "name not set"; } 

to orderitem add see difference makes

@override     public view getview(int position, view conertview, viewgroup parent){         if (convertview == null) {         layoutinflater inflater = (layoutinflater)                 context.getsystemservice(context.layout_inflater_service);           convertview = inflater.inflate(r.layout.order_object_layout, parent, false);         }         /** gather items view */         textview p_name = (textview) convertview.findviewbyid(r.id.product_name);         textview p_value = (textview) convertview.findviewbyid(r.id.product_value);         textview p_quantity = (textview) convertview.findviewbyid(r.id.product_quantity);         /** asign data text views */         orderitem item = (orderitem) object.get(position);         p_name.settext(item.getname());         return convertview;     } 

also should be

class orderobjectadapter extends arrayadapter<orderitem>{ 

not

class orderobjectadapter<orderitem> extends arrayadapter<orderitem>{ 

Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -