Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8502863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:36:11+00:00 2026-06-11T01:36:11+00:00

I am working on an android project and I am trying to work out

  • 0

I am working on an android project and I am trying to work out how I can use fragments to make a tablet friendly UI for my app. But I am unsure how to update fragment B depending on what happens in fragment A. I know I need some sort of interface but I can’t work out how to implement it.

Basically, what I have is an activity called MainActivity which sets the layout for the fragments.

In landscape mode the XML file is.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <fragment android:name="com.BoardiesITSolutions.FragmentTest.FragmentA"
        android:id="@+id/list"
        android:layout_weight="1"
        android:layout_width="0px"
        android:layout_height="match_parent">
    </fragment>
    <FrameLayout android:id="@+id/viewer"
        android:layout_weight="1"
        android:layout_width="0px"
        android:layout_height="match_parent"
        android:background="?android:attr/detailsElementBackground">
    </FrameLayout>
</LinearLayout>

In portrait mode its

Currently the MainActivity just sets the content view to the XML file above using SetContentView within in the onCreate method. Below is how it looks.

Fragment layout

In the FragmentA class file it extends ListFragment and contains a ListView of items and what I want to be able to do is to update the textview within Fragment B based on what is selected in Fragment A.

Below is the code for fragment A.

@Override
    public View onCreateView(LayoutInflater inflator, ViewGroup container, Bundle savedInstanceState)
    {
        return inflator.inflate(R.layout.fragment_a, container, false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState)
    {
        super.onActivityCreated(savedInstanceState);

        myListView = getListView();

        ArrayList<String> arrayList = new ArrayList<String>();
        arrayList.add("Item1");
        arrayList.add("Item2");
        arrayList.add("Item3");

        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity().getApplicationContext(), 
                android.R.layout.simple_list_item_activated_1, arrayList);
        setListAdapter(arrayAdapter);

        View fragmentB = getActivity().findViewById(R.id.viewer);
        mDualPane = fragmentB != null && fragmentB.getVisibility() == View.VISIBLE;

        if (savedInstanceState != null)
        {
            mCurCheckPosition = savedInstanceState.getInt("curChoice", 0);
        }

        if (mDualPane)
        {
            myListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
            showDetails(mCurCheckPosition);
        }
    }

    @Override
    public void onListItemClick(ListView l, View view, int position, long id)
    {
        showDetails(position);
    }

    private void showDetails(int index)
    {
        mCurCheckPosition = index;
        if (mDualPane)
        {
            myListView.setItemChecked(index, true);
            FragmentB details = (FragmentB)getFragmentManager().findFragmentById(R.id.viewer);
            if (details == null || details.getShownIndex() != index)
            {
                details = FragmentB.newInstance(index);

                FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
                fragmentTransaction.replace(R.id.viewer, details);
                fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
                fragmentTransaction.commit();
            }
        }
        else
        {
            Intent intent = new Intent(getActivity(), FragmentBActivity.class);
            intent.putExtra("index", index);
            startActivity(intent);
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState)
    {
        super.onSaveInstanceState(outState);
        outState.putInt("curChoice", mCurCheckPosition);
    }

FragmentB contains the following code, this class extends Fragment

public View onCreateView(LayoutInflater inflator, ViewGroup container, Bundle savedInstanceState)
    {
        if (container == null)
        {
            return null;
        }
        View view = inflator.inflate(R.layout.fragment_b, container, false);
        return view;
    }

    public static FragmentB newInstance(int index)
    {
        FragmentB fragmentB = new FragmentB();
        Bundle args = new Bundle();
        args.putInt("index", index);
        //rgs.putString("content", content);
        fragmentB.setArguments(args);

        return fragmentB;
    }

    public int getShownIndex()
    {
        return getArguments().getInt("index", 0);
    }

And in the Activity file for FragmentB it contains the following

@Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
        {
            finish();
            return;
        }

        if (savedInstanceState == null)
        {
            FragmentB fragmentB = new FragmentB();
            fragmentB.setArguments(getIntent().getExtras());
            getFragmentManager().beginTransaction().add(android.R.id.content, fragmentB).commit();
        }
    }

As you can see from the screenshot above, I have the basis of the fragments working and when I click on each item, it shows what the currently selected item is, but I have no idea how to tell it to update the textview in fragment b based on what the user clicked from fragment a and how this is handled in both portrait and landscape mode.

Thanks for any help you can provide.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:36:13+00:00Added an answer on June 11, 2026 at 1:36 am

    You may override the onActivityCreated() method of FragmentB, find view by id of that TextView, and update it.

    Here’s a mock:

    public class FragmentB extends Fragment{
    
        //......
    
        @Override
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
    
            TextView textView = getActivity().findViewById(R.id.my_textview);
            textView.setText("Hello World!");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am working on a android project for my assignment. i am trying to
I am currently working on an android project and I am trying to create
i am working on a project with many activities but when trying to code
I'm working on an android project that involves native code and I'm trying to
I am working on android project and I am trying to show an AlertDialog
I am currently working on an android project. I am trying to have an
I'm trying to get AdMob working with my android app and I'm having some
I am currently working on an Android project where I'd have to use maven.
I am trying to run an android project on eclipse but every time I
I'm working on an Android project using API 7 and I'm trying to start

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.