我在以下代码中出现以下错误“无法解析符号'侦听器'”但似乎无法摆脱这种情况。有关为什么会出现此错误的任何想法?
public void onClick(View v) {
Spinner spr = (Spinner) findViewById(R.id.planspinner);
EditText editText6 =(EditText) findViewById(R.id.editText6);
TextView textView8 =(TextView) findViewById(R.id.textView8);
String selectedItem =(String) spr.getSelectedItem();
int intItemPosition =spr.getSelectedItemPosition();
if (selectedItem.trim().equals("*")){
float result = Float.parseFloat(editText6.getText().toString()) * Float.parseFloat(Integer.toString(planlist.get(intItemPosition).getCalories()));
textView8.setText(Float.toString(result));
}
Button button4 = (Button)findViewById(R.id.button4);
button4.setOnClickListener(listener);
}
答案 0 :(得分:1)
需要声明监听器:
private planOnClickListener myClickListener = new planOnClickListener();
与听众的适当链接:
Button button4 = (Button)findViewById(R.id.button4);
button4.setOnClickListener(myClickListener);