Created
April 17, 2018 01:21
-
-
Save jianastrero/80efcb2d8c332d7e19a2db3930698106 to your computer and use it in GitHub Desktop.
TUTORIAL 1: PT 3 - Views - EditText and ImageView
MainActivity.java
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.jianastrero.edittextimageview; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
final ImageView imageView = findViewById(R.id.imageView); | |
final EditText editText = findViewById(R.id.editText); | |
final TextView textView = findViewById(R.id.textView); | |
Button button = findViewById(R.id.button); | |
button.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
imageView.setImageResource(R.mipmap.ic_launcher); | |
String input = editText.getText().toString(); | |
textView.setText(input); | |
//Bonus: clears edittext when the button is clicked | |
input = ""; | |
editText.setText(input); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment