-
카테고리
-
세부 분야
모바일 앱 개발
버튼을 눌러도 왜 토스트 메시지는 안나올까요??
21.01.01 17:25 작성 조회수 46
0
삭제된 글입니다
답변을 작성해보세요.
0
이야이야
질문자2021.01.01
핸드폰 연결해서 하면 되네요.. 에뮬레이터가 문제가 있었나봐요
궁금한게 있는데 위에 제가한것처럼 바인딩을 사용하는게 좋을까요? 아니면 강사님처럼 findViewById를 사용하는게 좋을까요?
0
0
0
0
0
0
개복치개발자
지식공유자2021.01.01
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val testButton = findViewById<Button>(R.id.test)
testButton.setOnClickListener {
Toast.makeText(this, "정국버튼입니다.", Toast.LENGTH_LONG).show()
}
}
}
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">
<Button
android:id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
제가 예제를 하나 만들었는데 이걸 참고해보시겠어요?
0
이야이야
질문자2021.01.01
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="정국"/>
</LinearLayout>
//activity_photo.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".PhotoActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/photo"/>
</androidx.constraintlayout.widget.ConstraintLayout>
빌드시 오류는 없고 intent로 화면 전환 되어서 사진까지는 나옵니다.
PhotoActivity::class.java 말고 저는 액티비티를 만들때
PhotoActivity.kt로 생성했는데 강사님은 PhotoActivity.java로 만드셔서 여쭤본거였어욤
0
개복치개발자
지식공유자2021.01.01
binding.button.set ---
이 부분의 button이 xml에 파일에 button이라고 id가 되어 있어야 합니다~ xml파일도 보내주시면 좋을 것 같아요
0
개복치개발자
지식공유자2021.01.01
안녕하세요 이야이야님
확인해주셔야 하는 것이
1.혹시 에러가 나오거나, intent로 화면 전환이 이루어지나요??
2. xml파일에는 어떻게 되어 있나요?
그리고 PhotoActivity::class.java는 화면이 전환되는 문법같은 것이라고 생각해주시면 됩니다.
답변 10