有谁知道为什么这个程序不会显示吐司信息?
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);
我已经创建了一些 ImageButons 和其他元素并创建了 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(在我运行程序后)时,吐司不会显示?