У меня есть действие, которое имеет собственный imageView.В imageView я хочу вызвать метод из действия.
Возможно ли это?
MainActivity:
package com.example.helloworld;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
int score=0;
public void myFunction(){
Log.d("LOG","call from imageView " + (score++));
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a TextView" />
<com.example.MyImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
MyImageViewClass
public class MyImageViewClass extends ImageView {
public MyImageViewClass(Context context, AttributeSet attrs) {
super(context, attrs);
}
protected void onDraw(Canvas canvas) {
MainActivity.myFunction();
}
}
Другими словами, я хочу позвонить myFunction(in Activity)
из onDraw()
(в MyImageView)
Возможно ли это?