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
容易的問題!大家都在回答 –