Usman Ali Aslam
Usman Ali Aslam

Reputation: 5

how to set Onclick listner for footer layout

I have a footer.xml layout and I'm using it on most activities in my app. The problem is that it has some buttons. How can I implement a click listener for them, and use it everywhere?

Upvotes: 0

Views: 85

Answers (1)

V-rund Puro-hit
V-rund Puro-hit

Reputation: 5534

You can Inflact layout in your Activity. and then can perform Action on view of that layout.

Try this

LayoutInflater inflator = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view= inflator.inflate(R.layout.YOUR_FOOTER_LAYOUT, null);

Button btn = (Button) view.findViewById(R.id.YOUR_BUTTON_ID);

btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            //perform action
        }
    });

hope this works for you.

Upvotes: 1

Related Questions