Giter VIP home page Giter VIP logo

b4a-jsdataadapter's Introduction

B4A-JSDataAdapter

Adapter Wrapper for B4A (Basic4Android) Supports List and Cursor Adapter to be use in JSListView

Copy .jar, .xml to your additional library folder

The provided sample (source) requires library:

  • JSON

You can find the additional library in B4A Forum

Sample

Using List Adapter
'sample list from json file
Dim json As JSONParser
json.Initialize(File.ReadString(File.DirAssets, "drug_list.json"))
Dim dataSource As List = json.NextArray

'initialize adapter
adapter.Initialize("adapter", dataSource)

'set it on JSListView
listview.Adapter = adapter
Using Cursor Adapter
'sample sqlite connection	
cn.Initialize(File.DirInternal, "1.db", False)	
Dim cur As Cursor = cn.ExecQuery("SELECT * FROM MOCK_DATA")

'Initialize JSCursorAdapter and set cursor
Adapter.Initialize("adapter", cur)
listview.Adapter = adapter

Important events

_onGetView(position As Int, viewHolder As JSViewHolder) - this is the event where you will initialize your item layout, you will need to check if the container is null to reuse the existing viewholder.container.

Sub adapter_onGetView(position As Int, viewHolder As JSViewHolder)
    'we will load new layout if container is null
    If viewHolder.Container	= Null Then
        'load layout container (item layout)
        Dim p As Panel
        p.Initialize("")
        p.LoadLayout("layout")
        viewHolder.Initialize(p, 110dip, 100%x)

        'set layout
        lblDrugname.Width = 100%x - lblDrugname.Left - 10dip
        lblDrugname.Gravity = Bit.Or(Gravity.LEFT, Gravity.CENTER_HORIZONTAL)
        lblQuantity.Gravity = Gravity.CENTER

        'set view id
        viewHolder.setViewId(imgAvatar, 10)
        viewHolder.setViewId(lblDrugname, 20)
        viewHolder.setViewId(lblQuantity, 30)
        viewHolder.setViewId(btnAdd, 40)
        viewHolder.setViewId(btnMinus, 50)		
    End If
End Sub

_onBindView(position As Int, viewHolder As JSViewHolder) - this is the event where you will set/bind your data to your views

Sub adapter_onBindView(position As Int, viewHolder As JSViewHolder)
    If viewHolder.Container = Null Then Return

    'find view
    imgAvatar = viewHolder.findViewById(10)
    lblDrugname = viewHolder.findViewById(20)
    lblQuantity = viewHolder.findViewById(30)
    btnAdd = viewHolder.findViewById(40)
    btnMinus = viewHolder.findViewById(50)

    'bind data to view
    Dim mapData As Map = adapter.DataSource.Get(position)
    lblDrugname.Text = mapData.Get("drug_name")
    lblQuantity.Text = mapData.Get("quantity")
    'set position info on your view
    btnAdd.Tag = position
    btnMinus.Tag = position
    lblDrugname.Tag = position
End Sub

b4a-jsdataadapter's People

Contributors

salvadorjhai avatar

Stargazers

Abdul Cadre avatar Eka Puji Widiyanto avatar

Watchers

James Cloos avatar  avatar Abdul Cadre avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.