我有一个列表显示我创建的SQlite数据库的内容。但是,当我运行该功能从数据库中删除用户选择的项目之一时,项目仍会显示,直到我刷新视图(现在单击“主页”并重新进入视图)。我怎样才能让列表在用户删除项目时自动更新?如何从数据库删除项目时动态更新列表
这是我的删除功能和列表代码:
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();
}
}
私有函数复习():无效 {VAR 语句:=的SQLStatement新的SQLStatement(); var conn:SQLConnection = new SQLConnection(); stmt.sqlConnection = conn; conn.open(File.applicationStorageDirectory.resolvePath(“FlashCards.db”)); stmt.text =“SELECT * FROM cardItems”; //刷新列表在这里? stmt.execute(); myCardsList.dataProvider = new ArrayCollection(stmt.getResult()。data); }
列表:
<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>
感谢您的帮助! =)
我编辑的运算来提供信息。谢谢。 – Jordan 2011-02-26 01:43:18
当我尝试使用refresh()时,出现编译器错误(未定义的方法)。也许是因为这是一款手机应用程序? – Jordan 2011-02-26 01:45:46
我得到它的工作。将工作代码放在最上面。 – Jordan 2011-02-26 03:35:14