本文介绍了如何更新具有从 Sqlite 填充的 Gridview 的片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有两个选项卡的 ViewPager,其中包含片段.在第一个片段中,我有一个使用 Sqlite Db 填充的 Gridview.
I have a ViewPager with two tabs which holds fragment. Inside the first fragment, I have a Gridview which is being populated with Sqlite Db.
我的 Activity 中有一个自定义警报对话框,它是 Fragment 的父级.
I have an custom alertdialog in my Activity, which is the parent of the Fragments.
当警报对话框关闭时,它会添加/删除/更新 Sqlite Db:
When the alertdialog closes, it either adds/removes/updates the Sqlite Db:
DataBaseHelper dbh = DataBaseHelper(this);
...
positiveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dbh.addVal(new TheData(editName.getText().toString(), editAge.getText().toString())); //adds a row to the Sqlite Db
dialog.dismiss();
//on dismiss, refresh the Fragment, which in turn will display the updated GridView.
}
});
...
如何更新完成以下内容:
How can I update complete the following:
//on dismiss, refresh the Fragment, which in turn will display the updated GridView.
推荐答案
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.detach(frag).attach(frag).commit(); //frag is my Fragment instance...
每次对话框关闭时,它都成功了……简单易行!
Each time the dialog closed and it did the trick... simple and easy!
这篇关于如何更新具有从 Sqlite 填充的 Gridview 的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!