我有一个名为TouchImageView extends ImageView的类,并且可以检测用户单击它的位置。如果有兴趣,我想在Detailed_Image_Activity上调用将更新WebView的方法。我该如何实现?

我发现了一些有关使用观察者和可观察对象的想法,但我不知道该怎么做。我找到了此解决方案Equivalent of iOS NSNotificationCenter in Android?,但无法使其正常运行

这是我在TouchImageView类中的代码...

switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if(isPointOfInterest) {
            //The code below is used to update the WebView
            //The task called below exists in the Detailed_Image_Activity
            DownloadHighlightBackground HighlightDownloaderTask = new DownloadHighlightBackground();
            HighlightDownloaderTask.execute(new String[] { arg1.toString() });
        }
}

最佳答案

尝试这个,

您可以通过这种方式从视图中获取活动。

((MyActivity)getContext()).method_name();

09-10 02:26
查看更多