我已经阅读了一些关于此类问题的问题,但我无法解决。
我有这个:
public class Classwork extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_homework);
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
}
public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a DummySectionFragment (defined as a static inner class
// below) with the page number as its lone argument.
Fragment fragment = new DummySectionFragment();
Bundle args = new Bundle();
args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
args.putInt("posizione", position);
fragment.setArguments(args);
return fragment;
}
@Override
public int getCount() {
//code for number of pages
}
@Override
public CharSequence getPageTitle(int position) {
//code for return the title
}
}
public class DummySectionFragment extends Fragment {
public static final String ARG_SECTION_NUMBER = "section_number";
public DummySectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//query to populate ListView
//ListView with CustomAdapter
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> myAdapter, View myView, int myItemInt, long mylng) {
//Start new activity DialogDeleteAddGradeCopy
}
});
myDbHelper.close();
return rootView;
}
}
}
我已经使用 Eclipse 向导创建了它。DummyFragment 包含一个 ListView,使用 SQLite 查询填充(正确)。通过单击 ListView 的一个项目,将显示一个“对话框”(实际上是一个具有对话框样式的活动)。
对话:
public class DialogDeleteAddGradeCopy extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//retrive data form Intent for the update in the db
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
//update the db
finish();
}
}
});
}
此对话框允许用户更新(使用 db 查询)单击项目的值之一。一切正常,除了片段的更新。更新查询没问题(关闭对话框时数据库是最新的),但是要更新片段,我需要向右或向左滑动两次并返回(通过这种方式重新创建片段,所以一切正常美好的)。
我如何强制更新/重新创建片段?
提前致谢。
对不起,我的英语不好...