Hi friends,
Below is a very simple code :
-----------------------------------------------------
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
static final String TAG_I = "LOG_I";
private Button btn;
aOverride
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i(TAG_I, "onCreate : Test !");
btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(this);
}
aOverride
public void onClick(View v) {
if (v == btn)
{
Toast.makeText(this, "Click ok", Toast.LENGTH_LONG).show();
}
}
-----------------------------------------------------
In this code, the type of btn is Button and the type of v is View.
In the Android Framework, Button extends TextView and TexteView extends View, ok, but there :
if (v == btn)
we compare an object of type Button with an object of type View, how is this possible?
Possible answer: Button extends TextView and TextView extends View, so btn also View type? Right ?
Below is a very simple code :
-----------------------------------------------------
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
static final String TAG_I = "LOG_I";
private Button btn;
aOverride
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i(TAG_I, "onCreate : Test !");
btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(this);
}
aOverride
public void onClick(View v) {
if (v == btn)
{
Toast.makeText(this, "Click ok", Toast.LENGTH_LONG).show();
}
}
-----------------------------------------------------
In this code, the type of btn is Button and the type of v is View.
In the Android Framework, Button extends TextView and TexteView extends View, ok, but there :
if (v == btn)
we compare an object of type Button with an object of type View, how is this possible?
Possible answer: Button extends TextView and TextView extends View, so btn also View type? Right ?