Question

Im using a FragmentActivity in my app. While accessing it shows one panel the list is created in a new activity but, when i run in a tablet, two panels are present in it, but refuses to load the second panel.

"ItemDetailFragment" is the FragmentActivty that implements an OnItemClickListener, it was originally type "Fragment" when i created the project.

I am getting two errors, one in ItemListActivity

if (mTwoPane) {
            Bundle arguments = new Bundle();
            arguments.putString(ItemDetailFragment.ARG_ITEM_ID, id);
            //ItemDetailFragment fragment = new ItemDetailFragment();
            ItemDetailFragment fragment = new ItemDetailFragment();
            fragment.setArguments(arguments);
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.item_detail_container, fragment)
           //The method replace(int, Fragment) in the type FragmentTransaction 
           //is not applicable for the arguments (int, ItemDetailFragment)
           // Change type of 'fragment' to 'Fragment'
                    .commit();

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

and the exact same error in "ItemDetailActivity" with ".add" causing the error

 Bundle arguments = new Bundle();
        arguments.putString(ItemDetailFragment.ARG_ITEM_ID,
                getIntent().getStringExtra(ItemDetailFragment.ARG_ITEM_ID));
        ItemDetailFragment fragment = new ItemDetailFragment();
        fragment.setArguments(arguments);
        getSupportFragmentManager().beginTransaction()
                .add(R.id.item_detail_container, fragment)
                .commit();

please give me any suggestion as this is the first time i have worked with "Fragment"s.

No correct solution

OTHER TIPS

I assume this is the error message you get:

The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, ItemDetailFragment) Change type of 'fragment' to 'Fragment'

Have you tried doing what the error message suggest you do?

ItemDetailFragment fragment = new ItemDetailFragment(); // This does not work
Fragment fragment = new ItemDetailFragment(); // This works!

If you at a later stage need to use methods exclusive to ItemDetailFragment, you can always cast fragment back to an ItemDetailFragment-object. Like this:

((ItemDetailFragment) fragment).someMethod();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top