【问题标题】:Can't figure out how to display seekbar value in Android Studio无法弄清楚如何在 Android Studio 中显示搜索栏值
【发布时间】:2021-07-22 23:43:47
【问题描述】:

所以我有一个搜索栏,我希望搜索栏的值显示在屏幕上,但 android studio 不明白我描述搜索栏和文本的 ID 是什么(ID 被星号包围)

所有被星号包围的代码都是红色的,解释器看不懂。有什么帮助吗?

class MainActivity : AppCompatActivity() {
private var textView: TextView? = null
private var progressBar: ProgressBar? = null
private var seekBar: SeekBar? = null
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.*activity_mq1*)
    textView = findViewById<View>(R.id.*textViewQ1*) as TextView
    progressBar = findViewById<View>(R.id.*progressBar*) as ProgressBar
    seekBar = findViewById<View>(R.id.*seekBarQ1*) as SeekBar
    seekBar!!.setOnSeekBarChangeListener(object : OnSeekBarChangeListener {
        override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
            progressBar!!.progress = progress
            textView!!.text = "$progress%"
        }

        override fun onStartTrackingTouch(seekBar: SeekBar) {}
        override fun onStopTrackingTouch(seekBar: SeekBar) {}
    })
}

【问题讨论】:

    标签: java android android-studio kotlin


    【解决方案1】:

    您的 MainActivity 是否与您在清单中声明的​​包相同?默认资源包是 manifest 中声明的资源包。

    例如,如果清单中有 com.aaa 作为包,而 MainActivity 在 com.bbb 中,则必须在 MainActivity 中导入资源包,类似于

    import com.aaa.R
    

    【讨论】:

    • 哦,我是编码新手,所以请耐心等待,但在我所有的 kotlin 文件中,它们都导入了包
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-23
    • 2014-09-03
    • 2011-09-15
    • 1970-01-01
    • 2014-12-18
    • 2017-10-26
    • 2019-04-13
    相关资源
    最近更新 更多