gpt4 book ai didi

java - ButtonClickListener 无法转换为 OnClickListener

转载 作者:行者123 更新时间:2023-12-01 11:27:48 25 4
gpt4 key购买 nike

这段代码有什么问题?它不起作用:它给出了 2 个错误。

  1. 错误:找不到符号类 onClickListener

  2. 错误:类型不兼容:MainActivity.ButtonClickListener 无法转换为 OnClickListener

<小时/>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scr =(TextView) findViewById(R.id.textView );

int idList[] ={R.id.button ,R.id.button2, R.id.button3,R.id.button4,R.id.button5,R.id.button6,R.id.button7,R.id.button8,R.id.button9,R.id.buttonC,R.id.buttonAdd,
R.id.buttonSub,R.id.buttonEq};

for (int id:idList){
View v =(View) findViewById(id);
v.setOnClickListener(btnclick);
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

public void nMath(String str)
{
number1 =Float.parseFloat(scr.getText().toString());
op =str;
scr.setText("0");
}

public void getkeyboard(String str)
{
String ScrCurrent =scr.getText().toString();
if(ScrCurrent.equals("0"))
ScrCurrent ="";
ScrCurrent +=scr;
scr.setText(ScrCurrent);
}

public void nResult( ){
float number2 =Float.parseFloat(scr.getText().toString());
float result = 0;
if(op.equals("+"))
{
result =number1 + number2;
}
if(op.equals("-"))
{
result =number1 - number2;
}
scr.setText(String.valueOf(result));
}

private class ButtonClickListener implements onClickListener {
public void onClick(View v){
switch (v.getId()){
case R.id.buttonC:
scr.setText("0");
number1 = 0;
op ="";
break;
case R.id.buttonAdd:
nMath("+");
break;
case R.id.buttonSub:
nMath("-");
break;
case R.id.buttonEq:
nResult();
default:
String num =((Button) v).getText().toString();
getkeyboard(num);
break;
}
}
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

最佳答案

Java 类名大写:

private class ButtonClickListener implements View.OnClickListener {

关于java - ButtonClickListener 无法转换为 OnClickListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30676452/

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