Last active
July 1, 2019 01:44
-
-
Save Guilherme-HRamos/51e36160391e1b76d995dbb447640d48 to your computer and use it in GitHub Desktop.
Medium - Android/Java Interfaces like a Boss! - Callbacks pt ll
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
public class OpenLogFileActivity extends AppCompatActivity { | |
// some Activity code here | |
private void onOpenLogButtonClick() { | |
// Usando uma classe anônima como Callback | |
new OpenFileHelper("home/log.txt", new OpenFileHelperCallback() { | |
@Override | |
public void onFileOpenSuccess(File file) { | |
// do something with file | |
} | |
@Override | |
public void onFileOpenFailure(Throwable error) { | |
// show error to user | |
} | |
}); | |
} | |
} |
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
// Para usar o this no Callback, a classe deverá implementar o mesmo | |
public class OpenNotesFileActivity extends AppCompatActivity implements OpenFileHelperCallback { | |
// some Activity code here | |
private void onOpenNotesButtonClick() { | |
// Usando a própria classe como Callback | |
new OpenFileHelper("home/notes.txt", this); | |
} | |
@Override | |
public void onFileOpenSuccess(File file) { | |
// do something with file | |
} | |
@Override | |
public void onFileOpenFailure(Throwable error) { | |
// show error to user | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment