Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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