我有一个带有 EditText 和 Button 的简单布局。每当用户在 EditText 中输入特定单词时,我都希望出现祝酒词。我该怎么做?
Button btn;
EditText edt;
String Event;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn=(Button)findViewById(R.id.Button1);
edt=(EditText)findViewById(R.id.editText1);
btn.setOnClickListener(this);
Event=new String(edt.getText().toString());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(Event.equals("Test")){
Toast.makeText(this, "Great!",Toast.LENGTH_LONG).show();
}
}
}