Skip to content Skip to sidebar Skip to footer

Onclicklistener In Listview Populated With A Cursoradapter

I have a list view with 2 buttons on each row. I am using a cursoradpater to populate the list. I am also using the view holder pattern on newview() bindview(). My questions are: w

Solution 1:

You do not need the onListItemClick

You can try binding for each of your button an event in the adapter

finalButtonbutton= (Button) findViewById(R.id.button_id);
         button.setOnClickListener(newView.OnClickListener() {
             publicvoidonClick(View v) {
                 // Perform action on click
             }
         });

but probably this won't work on the list item, so you need a new aproach as is this described in the button documentation.

However, instead of applying an OnClickListener to the button in your activity, you can assign a method to your button in the XML layout, using the android:onClick attribute. For example:

<Button
     android:layout_height="wrap_content"
     android:layout_width="wrap_content"
     android:text="@string/self_destruct"
     android:onClick="selfDestruct" />

Now, when a user clicks the button, the Android system calls the activity's selfDestruct(View) method. In order for this to work, the method must be public and accept a View as its only parameter. For example:

publicvoidselfDestruct(View view) {
     // Kabloey
 }

The View passed into the method is a reference to the widget that was clicked.

Post a Comment for "Onclicklistener In Listview Populated With A Cursoradapter"