Skip to content

Instantly share code, notes, and snippets.

@ssaurel
Created April 24, 2017 07:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssaurel/3eb487570a7823b1ffcbd60cef396f88 to your computer and use it in GitHub Desktop.
Save ssaurel/3eb487570a7823b1ffcbd60cef396f88 to your computer and use it in GitHub Desktop.
MainActivity for the Morse Code App Tutorial
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