「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" にいて、新しい項目を arraylist に追加fram1
したsimple_list_item_1
ので、fram1 を更新したいと思います。
//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));
}