Search code examples
androidcustom-lists

How do i get Last TextView's Data from Row of customlistview?


I want to get Last textview from row that was being clicked by user

for ex,

I have clicked on first row then i will get "Single Cheese Topping"

So How Do i implement the onclicklistener any suggestion please.

enter image description here


Solution

  • For listview, you should use OnItemClickListener instead of OnClickListener. Here's you go.

    list.setOnItemClickListener(new OnItemClickListener(){
    
        @Override
        public void onItemClick(AdapterView<?> arg0, View viewGroup, int position,
                long arg3) {
            TextView lastTextView = (TextView)viewGroup.findViewById(R.id.last_textview_id);
            String lastText = lastTextView.getText().toString();
    
        }
    
    });
    

    Second parameter return your row layout ViewGroup. You just use findViewById to get the view you need to use from the row layout.