我一直在尝试在我的 kotlin 代码中添加“addonScrollListiner”,但它给了我一个空指针异常。我有一个片段,我在回收站视图中调用了 API 和填充数据。
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
mRootView = inflater.inflate(R.layout.fragment_notifications, container, false)
(activity as DifsBaseActivity?)!!.activityComponent.inject(this)
ButterKnife.bind(this, mRootView)
mPresenterNotification?.attachView(this)
mPresenterNotification?.getNotifications()
sweetUIErrorHandler = SweetUIErrorHandler(activity, mRootView)
setHasOptionsMenu(true)
setToolbarTitle("Notifications")
return mRootView
}
“getnotification”方法是从 api 获取数据。在“getnotification”的“onnext”方法中,我调用“displayNotifications”
override fun onNext(mResponse: Notifications?) {
mvpView!!.showProgressbar(false)
mvpView!!.displayNotifications(mResponse)
}
这就是“displayNotifications”方法中发生的事情。
override fun displayNotifications(mObjResponse: Notifications?) {
if (mObjResponse != null && mObjResponse.mListNotificaiton != null) {
System.out.println("" + mObjResponse)
if (mObjResponse.mListNotificaiton.size > 0) {
hideOnErrorUI()
mRvNotification.apply {
mLayoutManager = LinearLayoutManager(activity);
mLayoutManager!!.orientation = LinearLayoutManager.VERTICAL
mRvNotification?.layoutManager = mLayoutManager
mRvNotification?.setHasFixedSize(true)
mAdapterNotification?.setGroups(mObjResponse.mListNotificaiton)
mRvNotification.adapter = null;
mRvNotification?.adapter = mAdapterNotification
mAdapterNotification?.setItemClickListener { mView, position ->
if( mObjResponse.mListNotificaiton.get(position).objectType.trim().toLowerCase().equals("loan")){
// mListener!!.loadLoan(4986, "Active")
mListener!!.loadGroup()
}else if(mObjResponse.mListNotificaiton.get(position).objectType.trim().toLowerCase().equals("client")){
// mListener!!.loadClient( mObjResponse.mListNotificaiton.get(position).objectId, "Active")
mListener!!.loadGroup()
}
}
}
} else {
mRvNotification.adapter = null;
showOnErrorUI()
}
} else {
showOnErrorUI()
}
}
我无法确定我应该使用哪个“addonScrollListiner”
mRvNotification.addOnScrollListener(object : EndlessRecyclerViewScrollListener(mLayoutManager) {
override fun onLoadMore(page: Int, totalItemsCount: Int) {
}
})