버튼을 눌러도 왜 토스트 메시지는 안나올까요??
310
작성한 질문수 6
삭제된 글입니다
답변 10
0
핸드폰 연결해서 하면 되네요.. 에뮬레이터가 문제가 있었나봐요
궁금한게 있는데 위에 제가한것처럼 바인딩을 사용하는게 좋을까요? 아니면 강사님처럼 findViewById를 사용하는게 좋을까요?
0
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
//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
binding.button.set ---
이 부분의 button이 xml에 파일에 button이라고 id가 되어 있어야 합니다~ xml파일도 보내주시면 좋을 것 같아요
0
안녕하세요 이야이야님
확인해주셔야 하는 것이
1.혹시 에러가 나오거나, intent로 화면 전환이 이루어지나요??
2. xml파일에는 어떻게 되어 있나요?
그리고 PhotoActivity::class.java는 화면이 전환되는 문법같은 것이라고 생각해주시면 됩니다.
에뮬레이터 실행이 안됩니다.
0
303
1
kotlin-android-extensions 관련 질문
0
207
1
안드로이드 버전 문제로 컴파일 에러가 계속 발생합니다.
0
489
1
button_one_name이 자꾸 빨간색으로 표시가 되서요ㅠ
0
349
1
null exception
0
448
2
앱 실행 시 keeps stopping 에러
0
5348
1
unresolved reference 오류
0
407
2
파이어베이스에는 잘 저장 되는데 불러올때 null값이라고 나옵니다...
0
861
3
Property getter or setter expected
0
1665
2
MainListAdapter를 하는 과정에서 view binding
0
163
1
건들지마세요 누르면 소리나오는거 구현할때 build까지 무리없이 되었는데
0
393
8
저역시 id를 찾지못합니다
0
295
4
영상처럼 하면 id를 찾지 못합니다.ㅠㅠ
3
200
1
v7이 붉은 글씨로 뜨는데요.
0
187
1
githubapi 패키지는 어디서 가져온 거죠? 다운 받은건가요?
0
310
3
LayoutInflator from context 에서 에러 발생
0
293
1
Firebase.auth 없음
0
410
1
소문자 입력, 대문자 표기
0
280
0
andriox가 default로 잡혀있습니다.
0
245
1
<LinearLayout>에 에러가 발생합니다..
1
931
4
리스트 뷰
1
219
1
리스트뷰 화면문제
0
147
1
프리뷰 창
0
316
1
ImageView 에러
0
264
4





