我在“ActionBarMain.java”中创建了以下片段
FragMent1 fram1;
FragmentTransaction fragMentTra = null;
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if (tab.getText().equals("Collection")) {
try {
rl.removeAllViews();
} catch (Exception e) {
}
fram1 = new FragMent1();
fragMentTra.addToBackStack(null);
fragMentTra = getFragmentManager().beginTransaction().add(rl.getId(), fram1);
fragMentTra.commit();
}
//And in here I create a new activity
Intent intent = new Intent(this, AddBookActivity.class);
startActivity(intent);
所以很自然我应该能够执行findFragmentByTag(fram1)
现在我在“AddBookActivity”中,并且已经将一个新项目添加到一个fram1
打印出来的数组列表中simple_list_item_1
,所以现在我想刷新 fram1,我该如何在 AddBookActivity 中做到这一点?
//AddBookActivity.java
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.addBook:
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
Fragment newFragment = new FragMent1();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
//How do I find out the fragment id from findFragmentByTag(fram1)????
transaction.replace(R.id.your_fragment_id, newFragment);//Whats the id, I have the Tag that is fram1
transaction.addToBackStack(null);
transaction.commit();
return true;
case R.id.cancel:
super.finish();
return (true);
}
return (super.onOptionsItemSelected(item));
}