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 9168305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:35:48+00:00 2026-06-17T15:35:48+00:00

On Android 3.0 and above, the android team is driving hard that you should

  • 0

On Android 3.0 and above, the android team is driving hard that you should use fragments over activities. And I see this being useful, but I want to be able to handle click events in my app. I’m using a list fragment on the right side of my app, so doing an onclick (or any click listeners) happens in the activity that hosts the fragment. So I had to move from putting a item in XML to using the fragment manager.

In the design documents they show this picture:Misleading Photo

http://developer.android.com/training/basics/fragments/fragment-ui.html

What I want is the Fragment A/B tablet UI. However, nowhere in this page does it actually give you an example of doing this – it seems that fragment manager only works with ONE fragment at a time – which is entirely opposite of what the picture portrays. Which makes me think it uses in XML… but then how would I get an onclick? These documents don’t make a lot of sense to me. It shows one thing and then says something else. What if I wanted to remove fragment A on the tablet? Add fragment C that doesn’t yet exist? Is that even possible if you tried to use Fragment Manager????

I guess I don’t get if Fragment manager uses more than 1 fragment, and if it does, how am I supposed to use this to get an item in the picture like the tablet – the left (A) being a listview, and the right (B) being whatever. Without an ID of the fragment I don’t how to access it.

Not sure if this is relevant but here is some of my code:

Adds a fragment to the single framelayout I made like in the guide

//Activity              
FragLaunch launchPane = new FragLaunch();
                // In case this activity was started with special instructions from an Intent,
                // pass the Intent's extras to the fragment as arguments
                // firstFragment.setArguments(getIntent().getExtras());

                // Add the fragment to the 'fragment_container' FrameLayout
                getFragmentManager().beginTransaction()
                        .add(R.id.launch_frag_container, launchPane).commit();
            }

Also, in portrait mode of 7″ tablets, I want it to use a viewpager that is swipeable. It worked like a charm when I designed it in XML but now that I have to access the listfragment it doesn’t work (no way to access since I can’t have two fragments)

XML of FragLaunch’s content view:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:gravity="center_vertical"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/initial_directions"
        style="@style/textScalar.Roboto.Light"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/initial_directions"
        android:layout_marginBottom="30dp"
        tools:context=".Launch" />

</LinearLayout>

I want to have this one appear as Fragment A in the photo:
FragHistory.java/xml for fragment:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/spamhistory"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Spam History" />

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:drawSelectorOnTop="false" />

</LinearLayout>

Does anyone have any insight on this?

  • 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-17T15:35:49+00:00Added an answer on June 17, 2026 at 3:35 pm

    If you want your fragments to be able to communicate then you need to use interfaces, like this.

    For onClick events you simply set an onClickListener for the view that you need to receive the onClick event from. Like so:

    sampleView.setOnClickListener(new View.OnClickListener() {
    
        @Override
        public void onClick(View v) {
            //Your code here
        }
    });
    

    As for fragment transactions, it says somewhere in there (I can’t remember exactly where) that when two fragments are displayed on the screen at once (as with larger screens) that instead of swapping the fragments it simply updates it. All you have to worry about is making the correct calls. So if you want to remove fragment A just call remove(). Or if you want to replace it with fragment C call replace() and pass fragment C in as the parameter.

    Can you clarify your question about the ViewPager? What do you mean “have to access it”?

    Hope this helps!

    EDIT: I apoplogize, I misunderstood your question. Here’s kind of a quick run down of how to add more than one fragment to the screen at once.

    1. Perform a runtime check to make sure that the device screen is big enough to display more than one fragment.

    2. If the screen is big enough, set the content view to use a layout that has a FrameLayout for each fragment that you want to add.

    3. After that grab a reference to each fragment that you want to use.

    4. Then use the FragmentManager to add a fragment to each layout. Like this:

    FirstExampleFragment fragment1 = new FirstExampleFragment();
    SecondExampleFragment fragment2 = new SecondExampleFragment();
    
    getSupportFragmentManager().beginTransaction().add(R.id.example_framelayout1, fragment1)
    .add(R.id.example_framelayout2, fragment2).commit();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got few Activities that use @android:style/Theme.Holo.Light.NoActionBar as theme. API levels above 11 work
I'm creating an app that will support Android 2.2 and above. In that I
I have this issue with multiple Images upload with Android 3.x versions and above.
I want to program an Android app -for android 2.1 and above- that does
I'm developing an Android 3.1 and above application, but this question is not specific
I'm developing a graphics-intensive application for Android 2.2 and above. I know that starting
My users are slowly being migrated to ICS (Android 4.0 and above) and since
I am refering Android ListView Refresh Single Row However, to use the above link
I'm developing an Android 3.1 and above application. I have this code to download
I know that Mono on Android only officially supports Android 1.6 and above, but

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.