android - how to OnClick button in LinerLayout to Retreieve particular's row value? -


following code.i use spring json restful web service retrieve list of data , display @ adt.display mulriple rows of data works fine ^_^.

my question is,how retrieve particular item row's value on user click button row?

|  id   | description | button  | |  2    | iphone 5    |(submit) | |  3    | samsung tab |(submit) | 

lets user click on "submit" button on 2nd row, system know id 3.

hope advice

regards

public class mymainactivity extends listactivity{      @override     protected void oncreate(){...}      @override     protected void onstart(){         super.onstart();         new httprequesttask().execute();      }      public void pickactions(view v){      }      private class httprequesttask extends asynctask<void,void,arraylist<itemdetail>>{         protected arraylist<itemdetail> doinbackground(void... params){              final string url = "http://10.0.2.2:8080/restdata";             resttemplate resttemplate = new resttemplate();             resttemplate.getmessageconverters().add(new mappingjackson2httpmessageconverter());             list<itemdetail> resultlist = arrays.aslist(resttemplate.getforobject(url, itemdetail[].class));             arraylist<itemdetail> list = new arraylist<itemdetail>();             if(resultlist.size()>0){                 for(int i=0;i<resultlist.size();i++){                     itemdetail itemdetail = resultlist.get(i);                                       list.add(itemdetail);                  }             }              return list;         }          @override         protected void onpostexecute(arraylist<itemdetail> list) {          m_adapter = new thearrayadapter(mymainactivity .this,list);         setlistadapter(m_adapter);         }      }  } 

the adapter

public class thearrayadapter extends arrayadapter<itemdetail>{     private arraylist<itemdetail> objects;     private string currentsku;      public thearrayadapter(context context,arraylist<itemdetail> objects){          super(context,r.layout.activity_main_list,objects);          the.objects = objects;     }      public view getview(int position,view convertview,viewgroup parent){         view v = convertview;          //....//         itemdetail = objects.get(position);          if(i!=null){             textview itemid= (textview) v.findviewbyid(r.id.itemid)             button btn = (button) v.findviewbyid(r.id.submitbutton)              btn.setonclicklistener(new view.onclicklistener() {      @override     public void onclick(view v) {         // todo auto-generated method stub         //new listfruitactivity().pickactions(v);         //string s = currentsku;         v.getid();         system.out.println("selected: "+v.getid());         }     });           }        } } 

the main activity xml

<linearlayout     android:clickable="true"     ....>  <textview     android:id="@+id/itemid"     ....> </textview>  <button     android:id="@+id/submitbutton"     android:onclick="pickactions"     android:clickable="true"     ..../>    </linearlayout> 

one simple way use settag . can set item id on button using settag this

button btn = (button) v.findviewbyid(r.id.submitbutton) btn.settag(id); btn.setonclicklistener(new view.onclicklistener() {  @override public void onclick(view v) {     // retrieve button item id      int itemid = (integer)v.gettag();      // have id, other stuff based not id here     } }); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -