Question

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

Was it helpful?

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.

OTHER TIPS

    lv1.setOnItemClickListener(new OnItemClickListener (){

@Override
public void onItemClick(AdapterView<?> arg0, View view, int position,
                        long arg3) 

here arg0 has the name of the item at index presses. you can get the name like this

name=arg0.getItemAtPosition(position).toString();

and you are done

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top