https://github.com/random-guys/rv
Custom RecyclerView Adapter
https://github.com/random-guys/rv
adapter android infinite-scroll library loadmore recyclerview
Last synced: 6 months ago
JSON representation
Custom RecyclerView Adapter
- Host: GitHub
- URL: https://github.com/random-guys/rv
- Owner: random-guys
- Created: 2019-08-15T19:58:19.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-09-11T12:14:19.000Z (about 6 years ago)
- Last Synced: 2025-02-02T12:35:45.192Z (8 months ago)
- Topics: adapter, android, infinite-scroll, library, loadmore, recyclerview
- Language: Kotlin
- Size: 133 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rv
`rv` is a custom recyclerView adapter that enables `infinite scroll` by default and `load more` capabilities.
## Installation
Add the dependency :
```gradle
dependencies {
implementation 'com.random-guys:rv:0.0.1'
}
```## Usage
```kotlin
class MainActivity : AppCompatActivity(), LoadMoreListener {private val faker = Faker()
private var theNames = ArrayList()
private lateinit var namesAdapter: NamesAdapter
private lateinit var linearLayoutManager: LinearLayoutManager
private lateinit var recyclerScrollMoreListener: RecyclerScrollMoreListeneroverride fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)namesAdapter = NamesAdapter(this)
namesAdapter.loadMoreListener = thisfor (i in 0 until 1000) theNames.add(faker.name().nameWithMiddle())
namesAdapter.add(theNames.subList(0, 20))
linearLayoutManager = LinearLayoutManager(this)
recyclerView.layoutManager = linearLayoutManager
recyclerView.adapter = namesAdapterrecyclerScrollMoreListener = RecyclerScrollMoreListener(linearLayoutManager, namesAdapter)
recyclerView.addOnScrollListener(recyclerScrollMoreListener)
}override fun onLoadMore(page: Int, total: Int) {
if (theNames.size >= total) {
namesAdapter.add(theNames.subList(page * 10, (page * 10) + 10))
recyclerView.post { namesAdapter.notifyItemInserted(namesAdapter.itemCount) }
}
}
}
```## Contribution
The `BaseViewHolder` class can be extended to support multiple view types.```
Copyright (c) 2019 Random GuysLicensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```