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

  • Home
  • SEARCH
  • 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 7567783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:45:13+00:00 2026-05-30T14:45:13+00:00

I was looking into changing my solution to use Fragments instead of ActivityGroups and

  • 0

I was looking into changing my solution to use Fragments instead of ActivityGroups and found an example which allowed me to change the part of my ui depending on a ListView lying above it. What I want to do is have a ListView which, when an item is clicked, replaces itself so that only the new layout is visible – Is this possible?

Below you’ll see the relevant code example I am using :

public class FragmentTestActivity extends FragmentActivity implements OnItemClickListener 
{
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ListView l = (ListView) findViewById(R.id.number_list);
    ArrayAdapter<String> magzTitles = new ArrayAdapter<String>(getApplicationContext(),
                android.R.layout.simple_list_item_1,
                    new String[]{"Cupcake",
                             "TaberTHULE",
                             "Lite"});
    l.setAdapter(magzTitles);
    l.setOnItemClickListener(this);
}

public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
{
    Fragment testFragment = new TestFragment(position++);
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.the_frag, testFragment);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.addToBackStack(null);
    ft.commit();
}
}

main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frags"
>

<ListView
    android:id="@+id/number_list"
    android:layout_width="150dp"
    android:layout_height="match_parent"
    />

<fragment class="com.android.saket.fragments.TestFragment"
    android:id="@+id/the_frag"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    />

</LinearLayout>
  • 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-05-30T14:45:15+00:00Added an answer on May 30, 2026 at 2:45 pm

    This is possible, what I’d do is to use a Framelayout as the container and then have two different fragments which will be switched out (the switching happens in your activity). This is pretty straight forward and you should not have troubles finding examples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking into selector performance between $('#ID1, #ID2, #ID3') vs $('1X CLASS'). Which is faster?
By looking into the Open JPA website i've found that i can log the
I'm looking into using Visual Studio 2008's built in unit test projects instead of
I have been looking into IKVMing Apache's FOP project to use with our .NET
I'm looking into changing from Solr to ES. One of the things I can't
I am looking into changing the file name of hundreds of files in a
I'm looking into changing my application to load its xml format data files into
Preface Please note, I'm not looking for a code solution, but rather insight into
I'm looking into a restful design and would like to use the HTTP methods
Currently looking into learn new technology and silverlight is on the potential list. However,

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.