本文介绍了如何更新具有从Sqlite填充的Gridview的片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有两个选项卡的ViewPager,其中包含片段.在第一个片段中,我有一个Gridview,其中正在填充Sqlite Db.
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.
我的活动"中有一个自定义的Alertdialog,它是Fragments的父级.
I have an custom alertdialog in my Activity, which is the parent of the Fragments.
alertdialog关闭时,它要么添加/删除/更新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.
}
});
...
如何更新以下内容:
//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的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!