У меня есть простой проект, который может переключаться между представлениями. У меня есть файл mainActvity.kt
, который подключается к main_actvity.xml
, затем у меня есть файл profile.kt
, который подключается к fragment_profile.xml
. Мне нужно добавить profile.kt
в androidManfist.xml
файл, кто-нибудь знает, как это сделать? Поэтому, когда я нажимаю button
, text
из textView
должен превратиться в "Hi how are you doing?"
. У меня есть другие файлы, потому что, когда я пытаюсь найти элемент с идентификатором в MainActvity.kt
, это выдаст мне ошибку null В заключение проблема, с которой я сталкиваюсь, заключается в том, что android не запускает файл, подключенный к fragment_profile.xml
. Я перепробовал почти все.
Это мой AndroidManfist.xml
файл
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lecture">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Profile"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
и вот мой profile.kt
файл
package com.example.lecture
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
class Profile(): AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.fragment_notifications)
val update = findViewById<Button>(R.id.updateButton)
update.setOnClickListener{ toaster() }
}
private fun toaster() {
val password = findViewById<TextView>(R.id.passwordAddressText)
password.text = "Hi how are you doing?"
}
}