开发者

How to update List dynamically when deleting item from database

I have a List that displays the contents of an SQlite database I have created. However, When I run the function to delete one of the user-selected items from the database, the items is still displayed until I refresh the View (right now by clicking 'home' and the reentering the View). How can I get the list to automatically update when the user deletes an item?

Here's my delete function and list code:

protected function getAllcards():void   // retrieve the cards from the DB and display
        {
            var stmt:SQLStatement = new SQLStatement();
            var conn:SQLConnection = new SQLConnection();
            stmt.sqlConnection = conn;
            conn.open(File.applicationStorageDirectory.resolvePath("FlashCards.db"));
            stmt.text = "SELECT cTitle FROM cardItems";
            stmt.execute();
            myCardsList.dataProvider = new ArrayCollection(stmt.getResult().data);

        }

        protected function myCardsList_creationCompleteHandler(event:FlexEvent):void  //executed when the List completes loading
        {
            getAllcards();
        }



protected function deleteButton_clickHandler(event:MouseEvent):void  // pushed delete button
        {
            if(myCardsList.selectedItem != null)
            {
            var stmt:SQLStatement = new SQLStatement();
            var conn:SQLConnection = new SQLConnection();
            stmt.sqlConnection = conn;
            conn.open(File.applicationStorageDirectory.resolvePath("FlashCards.db"));
            stmt.text= "DELETE FROM cardItems WHERE cTitle = ?";
            stmt.parameters[0] = myCardsList.selectedItem.cTitle;
            stmt.execute();
            refresher();
            }

        }

private function refresher():void { var stmt:SQLStatement = new SQLStatement(); var conn:SQLConnection = new SQLConnection(); stmt.sqlConnection = conn; 开发者_高级运维 conn.open(File.applicationStorageDirectory.resolvePath("FlashCards.db")); stmt.text = "SELECT * FROM cardItems"; //REFRESH LIST HERE? stmt.execute(); myCardsList.dataProvider = new ArrayCollection(stmt.getResult().data); }

List:

<s:List id="myCardsList" x="10" y="10" left="0" right="0" top="0" bottom="0" width="1004"
        height="500" 
        creationComplete="myCardsList_creationCompleteHandler(event)" enabled="true">
    <s:itemRenderer>
        <fx:Component>
            <s:MobileItemRenderer label = "{data.cTitle}"/>  // The Application is a mobile app
        </fx:Component>
    </s:itemRenderer>
</s:List>

Thanks for any help! =)


Could you show where you're doing the assignment of the dataprovider for the myCardsList? As a blind guess maybe this would work:

myCardsList.dataProvider.refresh(); //Normally used to apply a sort or filter function

Shaun

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜