Android visual components such as EditText
, Button
, and others have Listeners to handle events triggered by user actions.
Thus, in the method corresponding to the event, it is always necessary to pass a View
as a parameter. Here's a small example:
Button btn = (Button) findViewById(R.id.botaoMsg);
btn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View view)
{
EditText edtMsg = (EditText) findViewById(R.id.edtMsg);
String msg = edtMsg.getText().toString();
if (!msg.trim().isEmpty()) Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
else Toast.makeText(getApplicationContext(), "Digite uma mensagem!", Toast.LENGTH_SHORT).show();
}
});
Note that in the onClick()
method the view
variable was not used, and in the findViewById()
method you are looking for a EditText
that might be a View.
This is where my doubts arise regarding the View
class and the View on Android.
Questions
View
is on Android? >
View
?