How to add onclick event to button in list added by addFooterView?

I am using listview with my own database. Before adding the main elements of the list to the list and configuring the adapter, I add a footer with addFooterView () to the list. The footer is a regular list item with a custom view and two buttons.

And here is my problem:

How can I add an onClick () event to these buttons? I tried it in the getView () method of my base adapter, but this does not work.: /

I need these two buttons at the bottom of my list as back and forward buttons, because I do not want too many elements at once in the list.

THX

+5
source share
1 answer

View, , Button findViewById() onClick().

, XML-:

View footer = View.inflate(this, R.layout.footer, null);
getListView().addFooterView(foot, null, false);

Button forward = footer.findViewById(R.id.forward);
forward.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        // Perform action on click
    }
});

, , .

+21

All Articles