intdelay
在代码的开头被初始化为1000
。 我试图确保intdelay
的值由编辑框中的值更新,方法是单击按钮时添加一个烤面包。 但是当我运行应用程序,我得到以下问题:按钮内的按钮OnclickListener不起作用
Error:(46, 22) error: no suitable method found for makeText(<anonymous OnClickListener>,String,int)
method Toast.makeText(Context,CharSequence,int) is not applicable
(argument mismatch; <anonymous OnClickListener> cannot be converted to Context)
method Toast.makeText(Context,int,int) is not applicable
(argument mismatch; <anonymous OnClickListener> cannot be converted to Context)
这是我的代码的一部分:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
delayedttxt=(EditText)findViewById(R.id.delayedttxt);
String delay=delayedttxt.getText().toString(); //this will get a string
try{
int intdelay = Integer.parseInt(delay);
}catch(NumberFormatException ex){ // handle your exception
}
Button btn=(Button)findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
flashLight.switchFlash();
Toast.makeText(this,"your integer is " + intdelay , Toast.LENGTH_LONG).show();
}
});
我该如何解决呢?
调试你的代码,我认为flashLight.switchFlash();这有个例外 – YUVRAJ
容易的问题!大家都在回答 –