Corona 在 newScrollView 中显示来自数据库的文本

Corona show text from database in newScrollView

我正在尝试从 SQLite 数据库中提取一些数据到 Corona newScollView。

我设法在 tableView 中从数据库中获取数据,所以我认为代码对于 newScrollView 应该几乎相同。

它一直说该行是空的,但事实并非如此。有帮助吗?

代码如下:

function scene:create( event )

local sceneGroup = self.view   

local function scrollListener( event )

    -- Get reference to the row group
    local row = event.row

    local options_metni = 
    {
        parent = row,
        text = row.params.Metni,
        x = 0,
        y = 0,
        font = native.systemFont,
        fontSize = 16
    }

    local metniObject = display.newText(options_metni)
    metniObject:setTextColor(0)
    metniObject.x = display.contentCenterX
end

---------------------
-- CREATE SCROLLVIEW
---------------------
local scrollView = widget.newScrollView
{
    left = 0,
    top = 0,
    width = display.contentWidth,
    height = display.contentHeight / 2,
    topPadding = 200,
    bottomPadding = 50,
    horiontalScrollDisabled = true,
    verticalScrollDisable = false,
    listener = scrollListener,
}
sceneGroup:insert(scrollView)


---------------------
-- GET DATA FROM DB
---------------------
for row in db:nrows("SELECT baslik FROM dua LIMIT 1") do

if row.data == nil then
    print(" NO DATA FOUND ")
end

    local rowParams = 
    {
        duaID       = row.dua_id,
        Metni       = row.baslik,
    }
end
end

您需要在scrollView 中插入一个对象,它不像tableView 那样工作。在创建显示对象并从 row.baslik:

设置文本的地方试试这个
for row in db:nrows("SELECT baslik FROM dua LIMIT 1") do
    local text = display.newText( tostring( row.baslik ), 0, 0, native.systemFont, 16 )
    scrollView:insert( text )
end