728x90
# 실행 화면
# activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"/>
</LinearLayout>
# MainActivity.java
package kr.ac.skuniv.keyeventtest;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Toast toast = null;
EditText editText;
String string;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("2018305065 전유정");
editText = (EditText) findViewById(R.id.edit_text);
editText.setInputType(0);
editText.setOnKeyListener(new View.OnKeyListener(){
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
string = editText.getText().toString();
if(toast != null) toast.cancel();
toast = Toast.makeText(getApplicationContext(), string, Toast.LENGTH_SHORT);
toast.show();
return false;
}
});
}
}
반응형
'전공 공부 > 안드로이드프로그래밍' 카테고리의 다른 글
2개 액티비티 (그림 선택하면 액티비티에 확대되어 정보 출력) (0) | 2021.01.07 |
---|---|
RadioButton, EditText (계산기) (0) | 2021.01.07 |
버튼 (사진 회전) (0) | 2021.01.07 |
LinearLayout (버튼 배열) (0) | 2021.01.07 |
TextView 작성 (0) | 2021.01.07 |