Defining a Class and Inherit in a Subclass

One of the cool aspects of the Java language is the definition of classes and the use of sub-classes where inheritance are passed in between elements.

public class MainActivity extends Activity {

private EditText mNameField;
private Button mStartButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mNameField = (EditText)findViewById(R.id.nameEditText);
mStartButton = (Button) findViewById(R.id.startButton);

mStartButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = mNameField.getText().toString();
Toast.makeText(MainActivity.this, name, Toast.LENGTH_LONG).show();
}
});

Being able to pass data from user inputs and understanding the process of data-pass through is critical in Android development. Android SDK makes it a little easier to set up the code as it is intuitive to the declaration of variables and intent of activities.

Leave a Comment

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s