Recycler List View
An extension for rendering larger data sets efficiently using RecyclerView
for AppInventor & Distros.
Documentation
Events
Event raised to create UI. Don’t bind any data to the UI here.
Parameters
root : AndroidViewComponent
Event raised to bind data to UI.
Parameters
root : AndroidViewComponent
position: Current position.
Functions
Initialize
RecyclerList
inside a layout.
Create component inside a layout. For more details see: Dynamic Components
Create components inside a layout using JSON template. See Creating Templates
Set properties of a component.
Returns the root AndroidViewComponent of a child component.
Find a component using tag inside a root component. Returns AndroidViewComponent.
Set unique id of a component.
Get unique id of a component.
Returns true if the given component is dynamic.
Scroll to position.
Properties
Get / Set data count.
Recycler layout managers.
Recycler snap helpers.
Use these blocks to define layout orientation of recycler list.
Get position of first and last partially and fully visible items.
Sample
We will create a simple project that renders buttons inside card. When a button is clicked, it shows snackbar with the id of the button.
Preview
UI
Blocks
- Lets start by initializing the recycler view inside ListContainer. We will use
GridLayoutManager
because we want to create multiple columns. If you want to create single coulmn lists, useLinearLayoutManager
instead. To create a Masonry Layout, useStaggeredLayoutManager
. Next we will useNoSnapHelper
as we don’t wan’t any snapping. Moreover, snapping only works withLinearLayoutManager
. UseLinearSnapHelper
to snap items to center &PagerSnapHelper
to create a ViewPager snap effect. Next set reverse to false and set spanCount (Number of columns) to 3. Next set the count to 90.
-
We need to inflate our UI inside
OnCreateView
. Remember: only create UI, don’t bind any data here. The parameterroot
is actually aVerticalArrangement
. You can style root view just as you would style a vertical arrangement. Now we will create components usingCreateComponent
block. It takes a layout in which you want to create view, the name of the component, a tag to identify the component inside root view and properties in either a dictionary block or a json string.To get a component reference using the root view, use
GetComponent
block and pass itroot
view and tag of the desired component.
-
Inside
OnBindView
event, we will bind data to the UI. Here we have access to theroot
view andposition
. Here we will set the position as text of the button by usingSetProperties
block.To handle click events on a component, it is recommended to set a unique id by joining component name with the position to that component using
SetUniqueId
block so that you can access theposition
later inOnClick
event.
- Now we can handle click events using
Any Button.OnClick
event fromAnyComponent
section. First we will verify whether the click event was not already handled and the component is dynamic usingIsDynamic
block. Next we will save the uique id of button toid
variable by usingGetUniqueId
block. We will also create a position variable. To extract the position from unique id, we will replace the wordbutton
from unique id. Now we can use this position to show a snackbar.
Project Files
- APK File : RecyclerListView.apk (5.2 MB)
- AIA File: RecyclerListView.aia (82.4 KB)
Download Extension
1.0.0
- AIX File: com.dreamers.recyclerlist.aix (78.5 KB)
Latest Version
- AIX File : Github