【问题标题】:Unresolved Reference on recyclerView not working?recyclerView 上的未解决参考不起作用?
【发布时间】:2021-07-22 11:50:13
【问题描述】:

我一直在使用我在网上找到的推送通知构建一个股票应用程序。 {Link}。我遇到了几个问题,我已经找到了答案并修复了......但是我无法弄清楚这里的问题是什么。这是我的 MainActivity 的问题

private fun setupRecyclerView() {
    with(recyclerView){
        layoutManager = LinearLayoutManager(this@MainActivity)
        adapter = mAdapter
        addItemDecoration(DividerItemDecoration(recyclerView.context, DividerItemDecoration.VERTICAL))
    }
}

我忽略了什么? with 的问题是“没有足够的信息来推断类型变量 R”。 其次是(recyclerView)“未解决的参考:recyclerView”,尽管它在我的布局中声明为@+id/recyclerView

下面的布局

 <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"
        android:background="#000"
        tools:context=".MainActivity">
    
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    
    </androidx.constraintlayout.widget.ConstraintLayout>

【问题讨论】:

    标签: android firebase kotlin pusher


    【解决方案1】:

    如下调整代码。

    private val pusher = Pusher("PUSHER_KEY", options)
    private val channel = pusher.subscribe("stock-channel")
    private lateinit var recyclerView : RecyclerView
    
        override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        recyclerView = findViewById(R.id.recyclerView)
        setupPrefs()
        pusher.connect()
        setupRecyclerView()
        setupPusherChannels()
        setupPushNotifications()
    }
    

    现在它会为你工作。 问题是您使用的是旧教程,该教程使用语法糖作为视图 ID。

    【讨论】:

      猜你喜欢
      • 2020-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-25
      • 2022-06-15
      • 2019-04-05
      相关资源
      最近更新 更多