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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:50:56+00:00 2026-06-16T21:50:56+00:00

I am new to the android technology.i want to build a custom ListView using

  • 0

I am new to the android technology.i want to build a custom ListView using Fragments. I have searched it on google but i am not getting it.So plzz Help me.

  • 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-16T21:50:57+00:00Added an answer on June 16, 2026 at 9:50 pm

    I in my application have a screen contating two list fragments on left and right and with custom list view. hope this is what u neeed , use these and let me know if it helps u or not?

    here is the class contatining fragments

      public class MoreChannelsActivity extends FragmentActivity 
        implements ChannelsMenuFragment.OnHeadlineSelectedListener {
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.news_articles);
    
        // Check whether the activity is using the layout version with
        // the fragment_container FrameLayout. If so, we must add the first fragment
        if (findViewById(R.id.fragment_container) != null) {
    
            // However, if we're being restored from a previous state,
            // then we don't need to do anything and should return or else
            // we could end up with overlapping fragments.
            if (savedInstanceState != null) {
                return;
            }
    
            // Create an instance of ExampleFragment
            ChannelsMenuFragment firstFragment = new ChannelsMenuFragment();
    
            // 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
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.fragment_container, firstFragment).commit();
        }
    }
    
    public void onArticleSelected(int position) {
        // The user selected the headline of an article from the ChannelsMenuFragment
    
        // Capture the article fragment from the activity layout
    
      /// ChannelsSubMenuFragment articleFrag = (ChannelsSubMenuFragment) getSupportFragmentManager().findFragmentById(R.id.channels_fragment);
    
    TestSubMenuFragment articleFrag = (TestSubMenuFragment) getSupportFragmentManager().findFragmentById(R.id.channels_fragment);
    
        if (articleFrag != null) {
            // If article frag is available, we're in two-pane layout...
    
            // Call a method in the ChannelsSubMenuFragment to update its content
          // articleFrag.updateArticleView(position);
               articleFrag.updateListView(position);
    
        } else {
            // If the frag is not available, we're in the one-pane layout and must swap frags...
    
            // Create fragment and give it an argument for the selected article
            TestSubMenuFragment newFragment = new TestSubMenuFragment();
            Bundle args = new Bundle();
            args.putInt(TestSubMenuFragment.ARG_POSITION, position);
            newFragment.setArguments(args);
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    
            // Replace whatever is in the fragment_container view with this fragment,
            // and add the transaction to the back stack so the user can navigate back
            transaction.replace(R.id.fragment_container, newFragment);
            transaction.addToBackStack(null);
    
            // Commit the transaction
            transaction.commit();
        }
       }
       }
    

    here is the xml containing fragments…

          <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
    
    <fragment
        android:id="@+id/menus_fragment"
        android:name="com.example.android.fragments.ChannelsMenuFragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" />
    <View
        android:layout_width="3px"
        android:layout_height="fill_parent"
        android:layout_marginTop="0dp"
        android:background="#FF909090" />
    
    <fragment
        android:id="@+id/channels_fragment"
        android:name="com.example.android.fragments.TestSubMenuFragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2" />
    
      </LinearLayout>
    

    here is the list activity class

     public class ChannelsMenuFragment extends ListFragment {
    OnHeadlineSelectedListener mCallback;
    
    // The container Activity must implement this interface so the frag can deliver messages
    public interface OnHeadlineSelectedListener {
        /** Called by ChannelsMenuFragment when a list item is selected */
        public void onArticleSelected(int position);
    }
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        // We need to use a different list item layout for devices older than Honeycomb
        int layout = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ?
                android.R.layout.simple_list_item_activated_1 : android.R.layout.simple_list_item_1;
    
        // Create an array adapter for the list view, using the AudioVideoChannelsList headlines array
        setListAdapter(new ArrayAdapter<String>(getActivity(), layout, AudioVideoChannelsList.Menus));
    }
    
    @Override
    public void onStart() {
        super.onStart();
    
        // When in two-pane layout, set the listview to highlight the selected list item
        // (We do this during onStart because at the point the listview is available.)
        if (getFragmentManager().findFragmentById(R.id.channels_fragment) != null) {
            getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        }
    }
    
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    
        // This makes sure that the container activity has implemented
        // the callback interface. If not, it throws an exception.
        try {
            mCallback = (OnHeadlineSelectedListener) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement OnHeadlineSelectedListener");
        }
    }
    
    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        // Notify the parent activity of selected item
        mCallback.onArticleSelected(position);
    
        // Set the item as checked to be highlighted when in two-pane layout
        getListView().setItemChecked(position, true);
        }
       }
    

    and here is the data class named AudioVideoChannelsList that we provided to list adapter

         public class AudioVideoChannelsList {
    
    static String[] Menus = {
        "Channel One",
        "Channel Two"
    };
    
    
    
    static String[] ChannelsList1 = {
       "Country",
       "Genre",
       "Language"
      };
    
        static String[] ChannelsList = {
        "Article One\n\nExcepteur pour-over occaecat squid biodiesel umami gastropub, nulla           laborum salvia dreamcatcher fanny pack. Ullamco culpa retro ea, trust fund excepteur eiusmod direct trade banksy nisi lo-fi cray messenger bag. Nesciunt esse carles selvage put a bird on it gluten-free, wes anderson ut trust fund twee occupy viral. Laboris small batch scenester pork belly, leggings ut farm-to-table aliquip yr nostrud iphone viral next level. Craft beer dreamcatcher pinterest truffaut ethnic, authentic brunch. Esse single-origin coffee banksy do next level tempor. Velit synth dreamcatcher, magna shoreditch in american apparel messenger bag narwhal PBR ennui farm-to-table.",
        "Article Two\n\nVinyl williamsburg non velit, master cleanse four loko banh mi. Enim kogi keytar trust fund pop-up portland gentrify. Non ea typewriter dolore deserunt Austin. Ad magna ethical kogi mixtape next level. Aliqua pork belly thundercats, ut pop-up tattooed dreamcatcher kogi accusamus photo booth irony portland. Semiotics brunch ut locavore irure, enim etsy laborum stumptown carles gentrify post-ironic cray. Butcher 3 wolf moon blog synth, vegan carles odd future."
    };
    
    static String[] ChannelsList2 = {
         "Country2",
         "Genre2",
         "Language2"
       };
      }
    

    here is the second list activity class

              public class TestSubMenuFragment extends ListFragment {
    
    // The container Activity must implement this interface so the frag can deliver messages
    public interface OnHeadlineSelectedListener {
        /** Called by ChannelsMenuFragment when a list item is selected */
        public void onArticleSelected(int position);
    }
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        // We need to use a different list item layout for devices older than Honeycomb
        int layout = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ?
                android.R.layout.simple_list_item_activated_1 : android.R.layout.simple_list_item_2;
    
        // Create an array adapter for the list view, using the AudioVideoChannelsList headlines array
        setListAdapter(new ArrayAdapter<String>(getActivity(), layout, AudioVideoChannelsList.ChannelsList1));
     }
    
    @Override
    public void onStart() {
        super.onStart();
    
        // When in two-pane layout, set the listview to highlight the selected list item
        // (We do this during onStart because at the point the listview is available.)
        if (getFragmentManager().findFragmentById(R.id.channels_fragment) != null) {
            getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        }
    }
    final static String ARG_POSITION = "position";
    int mCurrentPosition = -1;
    public void updateListView(int pos)
    {
        if(pos==0)
        {
         int layout = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ?
                 android.R.layout.simple_list_item_activated_1 : android.R.layout.simple_list_item_2;
    
         // Create an array adapter for the list view, using the AudioVideoChannelsList headlines array
         setListAdapter(new ArrayAdapter<String>(getActivity(), layout, AudioVideoChannelsList.ChannelsList1));
        }
        else
        {
            int layout = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ?
                    android.R.layout.simple_list_item_activated_1 :      android.R.layout.simple_list_item_2;
    
            // Create an array adapter for the list view, using the AudioVideoChannelsList headlines array
            setListAdapter(new ArrayAdapter<String>(getActivity(), layout, AudioVideoChannelsList.ChannelsList2));
    
        }
    }
    
    
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    
        // This makes sure that the container activity has implemented
        // the callback interface. If not, it throws an exception.
        try {
    
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement OnHeadlineSelectedListener");
        }
    }
    
    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        // Notify the parent activity of selected item
    
    
        // Set the item as checked to be highlighted when in two-pane layout
    
      }
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am creating a new android application.i am using the table layout. I have
I am a new android app developer and i want to use google map
Respected Users, I am new with android and SQLite technology. I am getting error
hi i am new android developer.i want to show image in viewFlipper.But it is
I am a relatively new Android developer but have gotten pretty familiar with the
i am new to the NFC technology. i have experience in developing Android appllicaions.
I am new to working on Android technology. I have to read XML files
I am relatively a new Android developer and I am not able to understand
I am new android app developer i want make app for tablets and phone
I am new to android technology, while developing application i need to debug the

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.