-1

I'm trying to put a button to delete a row of a listview. I've modified the layout of the single rows like this:

Row

With lst.setOnItemClickListener... I manage the click on the row, but I don't know how to click the button inside the list.

It can be done?

Víctor Martín
  • 3,352
  • 7
  • 48
  • 94
  • 2
    yes use custom adapter – KOTIOS Dec 03 '14 at 10:53
  • 1
    1st use Google, 2nd use Bing, 3rd search in Stackoverflow. This is answered many times. – brummfondel Dec 03 '14 at 10:54
  • Check : http://stackoverflow.com/questions/27183107/in-listview-setonlistitem-not-working/27183190#27183190 – Haresh Chhelana Dec 03 '14 at 10:57
  • Literally what listview was made for, to able to show any view combination in a list. In the adapter, you pass the activity as the onclicklistener to prevent a separate onclicklistener with an implicit reference from keeping your activity alive. Then do whatever like a regular method. – G_V Dec 03 '14 at 10:59

2 Answers2

0

Search on google "custom adapter"

Then the 5 first links :

Custom Adapter for List View

http://www.javacodegeeks.com/2013/06/android-listview-custom-adapter-with-imageview.html

http://www.learn-android-easily.com/2013/06/listview-with-custom-adapter.html

http://www.vogella.com/tutorials/AndroidListView/article.html

http://developer.xamarin.com/recipes/android/data/adapters/create_a_custom_adapter_for_contacts/

Community
  • 1
  • 1
agonist_
  • 4,890
  • 6
  • 32
  • 55
0

Override your adapter getview method to handle the button click.

public View getView(final int position, View convertView,
        ViewGroup parent) {
    LayoutInflater inflater = getLayoutInflater();
    View row = inflater.inflate(R.layout.vehicals_details_row, parent,
            false);
    Button deleteImageView = (Button)  row.findViewById(R.id.DeleteImageView);
    deleteImageView.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
        });
    }
}

In your listItem xml layout, set the button to have the following attribute and it will cause the list item to be clickable as well:

android:focusable="false"
SubinM
  • 394
  • 3
  • 7