Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
TEACHING-MATERIALS/Week_02_The_Java_language/MyVehicle/app/src/main/java/com/example/jianhuayang/myvehicle/MainActivity.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
42 lines (33 sloc)
1.31 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.jianhuayang.myvehicle; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.EditText; | |
import android.widget.Toast; | |
public class MainActivity extends AppCompatActivity { | |
private static final String TAG = "MyVehicleActivity"; | |
private EditText editTextMake; | |
private EditText editTextYear; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
} | |
public void onButtonClick(View view) { | |
editTextMake = (EditText) findViewById(R.id.inputMake); | |
editTextYear = (EditText) findViewById(R.id.inputYear); | |
String make = editTextMake.getText().toString(); | |
String strYear = editTextYear.getText().toString(); | |
Vehicle vehicle; | |
if (strYear.matches("")) { | |
vehicle = new Vehicle(make); | |
} else { | |
int intYear = Integer.parseInt(strYear); | |
vehicle = new Vehicle(make, intYear); | |
} | |
Toast.makeText(getApplicationContext(), vehicle.getMessage(), Toast.LENGTH_SHORT).show(); | |
Log.d(TAG, "User clicked " + Vehicle.counter + " times."); | |
Log.d(TAG, "User message is \"" + vehicle + "\"."); | |
} | |
} |