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

user3354708

Following is my code.I use spring JSON restful web service to retrieve list of data and display at ADT.Display mulriple rows of data works fine ^_^.

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

|  Id   | Description | Button  |
|  2    | iPhone 5    |(Submit) |
|  3    | Samsung Tab |(Submit) |

Lets say user click on "submit" button on 2nd row, so that system would know id is 3.

Hope someone 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 i = 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>
Libin

One simple way is to use setTag . You can set the item id on the button using setTag like this

Button btn = (Button) v.findViewById(R.id.submitButton)
btn.setTag(id);
btn.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
    // retrieve the button item id
     int itemId = (Integer)v.getTag();
     // now you have the id, do your other stuff based not the id here
    }
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

JQuery The value 'i' starts from 0 for every button in table but i need the row button onclick to start from a particular index

From Dev

Increase value of data row of particular ID on button click

From Dev

How to create Html to pdf on particular div onclick button in angularjs?

From Dev

How to access a particular row in a CSV file and update the value in the row?

From Dev

displaying the value of a particular row

From Dev

How to remove particular row from listview on button click(Android)

From Dev

How to select the particular row data in jsp using radio button

From Dev

Change color of a row on onclick of that particular row

From Dev

Return row number(s) for a particular value in a column in a dataframe

From Dev

Android cannot find method from button's onClick in ListView Row

From Dev

How to call a button's onClick() method in PhantomJS?

From Dev

How to count the number of times a value is in a column based on particular row values?

From Dev

How to retrieve the column index for every row that has a particular value in R?

From Dev

how to know the check box value of a particular row of a listview

From Dev

How to add a value from one table to a particular row in another table?

From Dev

How to select a particular value in row from a table in html

From Dev

How to pass value of particular row to controller method in asp .net mvc

From Dev

How can I remove value of particular row using angularjs

From Dev

how to get the value of a particular checkbox if it is checked when submitting a button?

From Dev

How to get row index number for particular name(s)?

From Dev

Disable particular row value in UIPickerView

From Dev

finding the next row with a particular value

From Dev

fetch column value of particular row

From Dev

How to get particular value in Edittext if i click particular row from listview

From Dev

How to do a sum of a column if a particular cell of each row matches a particular value?

From Dev

The value of this in onclick for a button

From Dev

Find value in different row and get it to particular row

From Dev

Find value in different row and get it to particular row

From Dev

How to call button's onclick before textarea's onFocusOut?

Related Related

  1. 1

    JQuery The value 'i' starts from 0 for every button in table but i need the row button onclick to start from a particular index

  2. 2

    Increase value of data row of particular ID on button click

  3. 3

    How to create Html to pdf on particular div onclick button in angularjs?

  4. 4

    How to access a particular row in a CSV file and update the value in the row?

  5. 5

    displaying the value of a particular row

  6. 6

    How to remove particular row from listview on button click(Android)

  7. 7

    How to select the particular row data in jsp using radio button

  8. 8

    Change color of a row on onclick of that particular row

  9. 9

    Return row number(s) for a particular value in a column in a dataframe

  10. 10

    Android cannot find method from button's onClick in ListView Row

  11. 11

    How to call a button's onClick() method in PhantomJS?

  12. 12

    How to count the number of times a value is in a column based on particular row values?

  13. 13

    How to retrieve the column index for every row that has a particular value in R?

  14. 14

    how to know the check box value of a particular row of a listview

  15. 15

    How to add a value from one table to a particular row in another table?

  16. 16

    How to select a particular value in row from a table in html

  17. 17

    How to pass value of particular row to controller method in asp .net mvc

  18. 18

    How can I remove value of particular row using angularjs

  19. 19

    how to get the value of a particular checkbox if it is checked when submitting a button?

  20. 20

    How to get row index number for particular name(s)?

  21. 21

    Disable particular row value in UIPickerView

  22. 22

    finding the next row with a particular value

  23. 23

    fetch column value of particular row

  24. 24

    How to get particular value in Edittext if i click particular row from listview

  25. 25

    How to do a sum of a column if a particular cell of each row matches a particular value?

  26. 26

    The value of this in onclick for a button

  27. 27

    Find value in different row and get it to particular row

  28. 28

    Find value in different row and get it to particular row

  29. 29

    How to call button's onclick before textarea's onFocusOut?

HotTag

Archive