android widget on click event

前端 未结 3 1624
不思量自难忘°
不思量自难忘° 2020-12-03 10:03

I have created widget in android and it successfully works, but now I want to use on click event of widget so that I can open new activity from that.

Help me

3条回答
  •  执念已碎
    2020-12-03 10:57

    Inside your layout, for that particular widget give

    android:onClick="your method name inside your activity"
    

    and in your activity, give:

    public void methodname(View view) {
           //give your intent code here
    }
    

    Note: When you call a method like this, your method should be of public and it should have a View object as parameter.

提交回复
热议问题