Created
April 24, 2017 07:47
-
-
Save ssaurel/3eb487570a7823b1ffcbd60cef396f88 to your computer and use it in GitHub Desktop.
MainActivity for the Morse Code App Tutorial
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.ssaurel.morseconverter; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
private TextView txt; | |
private TextView result; | |
private Button toMorseBtn; | |
private Button toAlphaBtn; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
txt = (TextView) findViewById(R.id.txt); | |
result = (TextView) findViewById(R.id.result); | |
toMorseBtn = (Button) findViewById(R.id.toMorseBtn); | |
toAlphaBtn = (Button) findViewById(R.id.toAlphaBtn); | |
toMorseBtn.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
String txtToConvert = txt.getText().toString(); | |
String convertedTxt = MorseCode.alphaToMorse(txtToConvert); | |
result.setText(convertedTxt); | |
} | |
}); | |
toAlphaBtn.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
String txtToConvert = txt.getText().toString(); | |
String convertedTxt = MorseCode.morseToAlpha(txtToConvert); | |
result.setText(convertedTxt); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment