gpt4 book ai didi

java - 未定义类型按钮的错误 setonclickListener

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

您好,我收到错误消息:

the method setonclickListener(new onclickListener(){}) is undefined for the type button

这是我的代码:

public class Sliding extends Activity {
/** Called when the activity is first created. */
private LinearLayout MenuList;
private Button btnToggleMenuList;
private int screenWidth;
private boolean isExpanded;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sliding);
MenuList = (LinearLayout) findViewById(R.id.linearLayout2);
btnToggleMenuList = (Button) findViewById(R.id.button1);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
screenWidth = metrics.widthPixels;

btnToggleMenuList.setonclickListener(new onclickListener() {
public void onclick(View v) {
if (isExpanded) {
isExpanded = false;
MenuList.startAnimation(new CollapseAnimation(MenuList, 0,(int)(screenWidth*0.7), 20));
}else {
isExpanded = true;
MenuList.startAnimation(new ExpandAnimation(MenuList, 0,(int)(screenWidth*0.7), 20));
}
}
});
}
}

谁能告诉我为什么?

最佳答案

替换这个

btnToggleMenuList.setonclickListener(new onclickListener() {
public void onclick(View v) {

通过

btnToggleMenuList.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

还要确保你有下面的导入语句

import android.view.View.OnClickListener; 

关于java - 未定义类型按钮的错误 setonclickListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18934439/

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