Raj
Raj

Reputation: 506

View OnClickListner at Application level Android

I am developing an android application where I stuck at some point. The problem is that I want to track the last action performed in app by tracking onClickListner. So is there any way to set OnclickListner for whole application and then track the last event time. Please Suggest me the way to do that. My assumption is to have a class which extends View class and this class should implement onClickListner. Then all of my buttons should set OnClickListner to Object of this class. but my application have more than 100 buttons so it will increase the complexity of the class. one more problem is that all buttons are performing their activity specific operations.doing all operations from one class will increase complexity.

I am looking to capture onclicklistner throughout the app and then log the event time then transfer the event to the activity where onclickListner was implemented.

Upvotes: 0

Views: 76

Answers (1)

cYrixmorten
cYrixmorten

Reputation: 7108

An idea might be to create your own OnClickListener, say

class LoggingOnClickListener implements OnClickListener {

    public void onClick(View view) {
        doLog();
    }
}

Now you just have to add super.onClick(view) to add logging to the Button clicks

button.setOnClickListener(new LoggingOnClickListener() {

    public void onClick(Button button) {
        //handle the click
        super.onClick(button);
    }    
}

The code might very well be flawed as I do not have my IDE open, but should just show the general idea.

Upvotes: 1

Related Questions