Android 检查横幅是否被按下
我试图找到一种方法来检查横幅(广告)是否被检查,但它更难接缝。
我尝试过
adView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO
}
});
,但它不起作用(我放置了调试打印,但它不起作用..)
然后我尝试创建一个 LinearLayout 来包装 adView 并将侦听器放在线性布局上,但它仍然不起作用。
然后我尝试创建一个包含所有显示的更大布局,并在其中添加 adView。我想在其中放置一个 onTouchListener ,并检查坐标,以检查添加是否被按下。但我真的不明白如何找到我的横幅的正确坐标(我创建了一个方法来获取 x 和 y 偏移以及用于放置横幅的重力)进行检查,我真的希望存在更好的方法。此外,我发现如果我按下横幅,该方法不会执行,但只有按下屏幕的其他部分时才会执行。
那么,有什么办法可以知道吗?我不在乎知道横幅页面是否已加载,或者是否重定向到市场或浏览器,我只需要知道横幅是否被按下。
也许设置一个在触摸屏幕时运行的检查,然后检查listner方法是否运行,如果没有运行,则触摸横幅可以工作,但我不知道如何实现它..
任何知道怎么做吗?
谢谢
I'm trying to find a method to check if a banner (ad) is checked, but it is more difficult that it seams.
I tried
adView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO
}
});
But it doesn't work(i put a debug print but it didn't work..)
Then i tried to create a LinearLayout that wraps the adView and putted the listener on the linear layout, but it still didn't work.
Then i tried to create a bigger layout that contained all the display, and added the adView in it. I thought to put a onTouchListener in it, and checking the coordinates, to check if the add was pressed. But i don't really understand the how to find the correct coordinates of my banner (i created a method that gets x and y offset and the gravity to use to place the banner) to check, and i really hope that a better way exists. In addition i found that the method is not executed if i press the banner, but only if other parts of the screen are pressed.
So, is there some way to know it? I don't care to know if the banner page was loaded, or if it redirected to the market or the browser, i just need to know if the banner was pressed.
Maybe setting a check that runs when the screen is touched, and than check if the listner method was run, and if it wasn't run that the banner was touched can work, but i don't know how to implement it..
Any idea how to do this?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不知道为什么其他人没有谈论你使用的是哪个adView?
大多数(就像我所知道的那样)提供了一个您可以提供的侦听器,该侦听器在点击广告时有回调。
例如,MobFox 有
setBannerListener(BannerListenerlistener)
并且该监听器有一个方法adClicked()
。其他提供商(如 admob、inmobi、mopub)都有类似的监听器,您可以设置。这应该是处理这个问题的方法,而不是侵入容器视图。
I don't know why other people haven't spoken about which adView you are using?
Most (like in all I know) provide a listener you can supply, that has a callback for when a ad is clicked.
MobFox for example has
setBannerListener(BannerListener listener)
and that listener has a methodadClicked()
. Other providers (like admob, inmobi, mopub) all have similar listeners you can set.That should be the way to handle this, not hacking into a containerview.
对于那些仍然不知道如何操作的人:
它使用 AdListener
For those who still didnt know how to:
Its using AdListener
您是否尝试过在点击事件中添加祝酒词?
该应用程序可以编译并运行吗?
您有重复的 id 吗?
Did you try putting a toast in your click event?
Does the app compile and run?
Do you have duplicate ids ?
好的,我解决了,由于我花了很多时间来寻找解决方案,所以我将其发布在这里,以便每个人都可以找到并使用它!
Ok, i solved, and since i lost quite a bit of time to find the solution, i post it here so that everyone can find and use it!