javascript - Android put ImageButtons in ArrayAdapter with unique onclick events -


i making list products in it. in each row of list there has button add product shoppinglist. doesn't work buttonlayout.addview i'm stuck whole day. hope can me.

this code arraylist

protected void onpostexecute(void v) {                           // ambil data dari json database         try {                            jsonarray jarray = new jsonarray(result);             arrayadapter<string> adapter = new arrayadapter<string>(displayproductlist.this, r.layout.list_item);                                            /*string productname = null;             string productprice = null; */                                       relativelayout buttonlayout = (relativelayout) findviewbyid(r.id.listitem);             hashmap<string,string> map = new hashmap<string,string>();             for(int i=0;i<jarray.length();i++)                         {                                                                                                                                                         jsonobject jasonobject = null;                                                                                            jasonobject = jarray.getjsonobject(i);                                                            map.put("productname" + integer.tostring(i),jasonobject.getstring("productname"));                                  map.put("productprice" + integer.tostring(i),jasonobject.getstring("productprice"));                              log.i("log_tag","mapsize" + map.size());                              log.i("log_tag","map productname" + map.get("productname" + integer.tostring(i)));                              log.i("log_tag","map productprice" + map.get("productprice" + integer.tostring(i)));                              final string productname = map.get("productname" + integer.tostring(i));                              final string productprice = map.get("productprice" + integer.tostring(i));                              log.i("log_tag","string productname = " + productname);                              imagebutton additem = new imagebutton(displayproductlist.this);                                                                   relativelayout.layoutparams lpfirst = new relativelayout.layoutparams(layoutparams.wrap_content,layoutparams.wrap_content);                                                               additem.setimageresource(r.drawable.content_new);                                                             additem.setid(i);                                                                                             log.i("log_tag","buttonlayout.addview(additem);");                              buttonlayout.addview(additem,i, lpfirst);                              additem.setonclicklistener(new onclicklistener()                             {                                 public void onclick(view v)                                 {                                     ordermanager.additem(1, productname, productprice, 3);                                 }                              });                               adapter.add(productname);                                                          }                                     listview listview = (listview) findviewbyid(r.id.listviewproduct);             listview.setonitemclicklistener(new onitemclicklistener()             {                                                    public void onitemclick(adapterview<?> parent, view view, int position, long id )                 {                     log.i("log_tag",view + integer.tostring(position) + long.tostring(id));                     log.i("log_tag", integer.tostring(view.getid()));                 };             });                                                   listview.setadapter(adapter); 

and xml didn't create button yet because button made in script (tell me if i'm wrong)

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/listitem" android:layout_width="match_parent" android:layout_height="50dip"     android:paddingright="40dip" >  <textview  android:id="@+id/productname" android:layout_width="wrap_content" android:layout_height="wrap_content"  android:textsize="24sp" android:layout_centervertical="true"     android:paddingleft="40dip" />  <textview  android:id="@+id/productprice" android:layout_width="wrap_content" android:layout_height="wrap_content"  android:textsize="24sp" android:layout_centervertical="true"     android:paddingleft="40dip" />  <edittext android:id="@+id/productvalue" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignparentright="true" android:layout_marginright="60dip" android:hint="@string/value" android:singleline="true" android:inputtype="number"   android:maxlength="2"   />  </relativelayout> 

any other comments on script welcome. i'm still beginner there's lot learn.

i forgot mention error. a: error parsing data java.lang.nullpointerexception

this logcat:

09-25 12:38:22.850: e/log_tag(4992): error parsing data java.lang.nullpointerexception error returns


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -