【问题标题】:Adding multiple files to androidManfist.xml将多个文件添加到 androidManfist.xml
【发布时间】:2020-04-11 13:42:16
【问题描述】:

我有一个可以在视图之间切换的简单项目。我有一个连接到main_actvity.xmlmainActvity.kt 文件,然后我有一个连接到fragment_profile.xmlprofile.kt 文件。我需要将profile.kt 添加到androidManfist.xml 文件有人知道该怎么做吗?因此,当我按下button 时,textViewtext 应该变成“Hi how are you doing?"。我有不同的文件,因为当我尝试在MainActvity.kt 中查找具有id 的元素时,它会给我错误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?"
        }
    }

【问题讨论】:

  • "我有一个 profile.kt 文件连接到 fragment_profile.xml。" – 如果profile 确实是Fragment,则不要在清单中列出它。清单中仅列出了 ActivityServiceBroadcastReceiverContentProvider 子类。
  • 它仍然不起作用我删除了使文件成为片段的命令并运行它。还是不行。
  • 这里没有足够的信息让我们能够确定您到底想要做什么,或者为什么它不起作用。请edit您的问题更好地解释问题,并包含任何相关代码和 XML。
  • 好的,我添加了代码并添加了更多关于我的问题的信息。这足够了吗,还是您希望我添加更多内容?

标签: android xml kotlin


【解决方案1】:

在你的 androidManfist.xml 中添加这个

<activity android:name=".profile" />

【讨论】:

  • 它对我不起作用。我有代码,当按下按钮时它应该更改文本,我知道它有效,因为我将启动文件更改为该文件并且它有效。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多