public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText text = (EditText)findViewById(R.id.editText1);
EditText text1 = (EditText)findViewById(R.id.editText2);
String userid = text.getText().toString();
String pass = text1.getText().toString();
Toast.makeText(getBaseContext(),"Entered"+userid+"and password entered is"+pass,Toast.LENGTH_SHORT).show();
}
});
}
代码执行成功,但是按钮被按下时没有任何反应。当我在Eclipse中聚焦于该行时,它会显示以下内容。
"The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (new
View.OnClickListener(){}, String, int)"
请告诉我,我需要做什么才能使它正常工作?
getBaseContext()
,而是使用了this
... 你应该尝试保存或清理你的代码。 - Sam