Java – Android: use anonymous classes to programmatically create click listeners

I see some examples of making textview clickable by setting onclick = "clickhandler" and clickable = "true". Is there any way to use anonymous classes instead of hard coding "clickhandler" methods in activities

resolvent:

You go

TextView tv = (TextView)findViewById(R.id.textview);
tv.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // do whatever stuff you wanna do here
    }
});

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>