gpt4 book ai didi

android - 覆盖 onClick 并使用默认的 onclick

转载 作者:行者123 更新时间:2023-11-30 03:11:59 28 4
gpt4 key购买 nike

我重写了 onClick(View) 方法,以便在单击时 View 大小会发生变化。View 是一个显示浏览器网页的 webView。我需要点击会改变大小,而且浏览器会响应(转到被点击的链接)。在目前的情况下,用户必须点击两次——一次是为了改变尺寸,一次是为了浏览器的响应,这还不够好。

我该怎么做?

谢谢!

这是我的代码:

@Override
public void onClick(View arg0) {
switch (arg0.getId()) {

case R.id.button2:
// If web2 is pressed the Relativelayout who contain the webView will
// take this parameters
lin1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT, 8));
lin2.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT, 2));
butt1.setVisibility(View.VISIBLE);
butt2.setVisibility(View.INVISIBLE);
lin1.bringChildToFront(butt1);
break;

case R.id.button1:
// If web2 is pressed the Relativelayouts who contain the webView will
// take this parameters

lin2.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT, 8));
lin1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT, 2));
butt1.setVisibility(View.INVISIBLE);
butt2.setVisibility(View.VISIBLE);
lin2.bringChildToFront(butt2);
break;
}
return ;
}

最佳答案

就个人而言,我认为将事件添加到 View 的正确方法不是使用开关,你为什么不尝试这样的事情:......所以这将是你的 View 监听器,我希望帮助

button1.setOnClickListener(new OnClickListener() {          
@Override
public void onClick(View arg0) {

//and your custom code is going to be here

}
});

关于android - 覆盖 onClick 并使用默认的 onclick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20787083/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com