このプログラムがトースト メッセージを表示しない理由を知っている人はいますか?
public class Main extends Activity implements OnClickListener{
/** Called when the activity is first created. */
ImageButton x = (ImageButton) findViewById(R.id.imageButton1);
ImageButton i = (ImageButton) findViewById(R.id.imageButton2);
ImageButton question = (ImageButton) findViewById(R.id.imageButton3);
いくつかの ImageButtons とその他の要素を作成し、onClick 関数を作成しました
public void onClick(View v) {
if(v.getId() == R.id.button1) // this works
{
Intent intent = new Intent(this, Second.class);
intent.putExtra("thetext", et1.getText().toString());
intent.putExtra("thesize", et2.getText().toString());
startActivity(intent);
}
if(v.getId() == R.id.imageButton2) // this wont work
{
Toast toastI = Toast.makeText(this, "Testing", 5000);
toastI.setGravity(Gravity.CENTER, 0, 0);
toastI.show();
}
ImageButton i (プログラムを実行した後) をクリックすると、トーストが表示されませんか?