mercredi 20 mai 2015

Replace master fragment using 'if (position == x)'

I have a dummy content list containing 3 items but I want each item to open its own activity rather than passing data to the detail fragment. How can I replace the master fragment with a list fragment of my own when a particular list item is clicked? Is it possible to use the if (position == x) statement for each of my items? The code below replaces the detail fragment but I want to replace the master fragment instead. I have not seen any tutorials on this as all the ones I've come across are associated with replacing the detail fragment, NOT the master fragment.

@Override
public void onItemSelected(String id) {
    if (mTwoPane) {
        Bundle arguments = new Bundle();
        arguments.putString(ItemDetailFragment.ARG_ITEM_ID, id);
        ItemDetailFragment fragment = new ItemDetailFragment();
        fragment.setArguments(arguments);
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.item_detail_container, fragment)
                .commit();

    } else {
        Intent detailIntent = new Intent(this, ContinentsListActivity.class);
        detailIntent.putExtra(ItemDetailFragment.ARG_ITEM_ID, id);
        startActivity(detailIntent);
    }
}

Aucun commentaire:

Enregistrer un commentaire