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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:34:49+00:00 2026-06-15T11:34:49+00:00

This is my main tab Activity: public class LocationTabActivity extends RoboSherlockFragmentActivity{ private MapFragment mMapFragment;

  • 0

This is my main tab Activity:

public class LocationTabActivity extends RoboSherlockFragmentActivity{



    private MapFragment mMapFragment;
    private MyListFragment mMyListFragment;

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        Exchanger.mMapView = (MapView)findViewById(R.id.mapView1);


        getSupportActionBar()

          .setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);



    ActionBar.Tab newTab0 = getSupportActionBar().newTab();

    newTab0.setText("Location");






    newTab0.setTabListener(new TabListener<MyListFragment>(
                    LocationTabActivity.this, "listFragment", MyListFragment.class));




    ActionBar.Tab newTab1 = getSupportActionBar().newTab();

    newTab1.setText("Map");





    getSupportActionBar().addTab(newTab0);

    //getSupportActionBar().addTab(newTab1);




    }



    public static class TabListener<T extends Fragment> implements ActionBar.TabListener {
        private Fragment mFragment;
        private final Activity mActivity;
        private final String mTag;
        private final Class<T> mClass;

        /** Constructor used each time a new tab is created.
          * @param activity  The host Activity, used to instantiate the fragment
          * @param tag  The identifier tag for the fragment
          * @param clz  The fragment's Class, used to instantiate the fragment
          */
        public TabListener(Activity activity, String tag, Class<T> clz) {
            mActivity = activity;
            mTag = tag;
            mClass = clz;
        } 

        /* The following are each of the ActionBar.TabListener callbacks */
        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft1) {
            // Check if the fragment is already initialized

            FragmentManager fragMgr = ((FragmentActivity) mActivity).getSupportFragmentManager();
            FragmentTransaction ft = fragMgr.beginTransaction();

            if (mFragment == null) {
                // If not, instantiate and add it to the activity
                mFragment = Fragment.instantiate(mActivity, mClass.getName());

                ft.add(android.R.id.content, mFragment, mTag);
            } else {
                // If it exists, simply attach it in order to show it
                ft.attach(mFragment);
            }
        }

        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub

        }



    }







}

This is my MyListFragment:

public class MyListFragment extends SherlockFragment {

    public static final String TAG = "listFragment";

    private final String[] mItems = { "item1","item2","item3" };

    ArrayList<Location> locations = new ArrayList<Location>();
    private View view;
    public MyListFragment() {}
    TextView address;
    @Override
    public void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setRetainInstance(true);

        Location location = new Location();
        location.address = "hello";

        locations.add(location);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup vg, Bundle data) {
        // Inflate the ListView layout file.

        view = inflater.inflate(R.layout.location_list_fragment,vg, false);
        address =(TextView) view.findViewById(R.id.address);
        final ListView locationListLayout = (ListView) view.findViewById(R.id.locationListLayout);

        LocationListAdapter locationList = new LocationListAdapter(getActivity(),R.layout.location_list_fragment,locations);
        locationListLayout.setAdapter(locationList);

        return view;
    }

    @Override
    public void onViewCreated(View arg0, Bundle arg1) {
        super.onViewCreated(arg0, arg1);




    }
}

This is my LocationListAdapter:

public class LocationListAdapter extends ArrayAdapter<Location> {

    public ArrayList<Location> locations;
    public Context c;


    public LocationListAdapter(Context context, int textViewResourceId,ArrayList<Location> objects) {

        super(context, textViewResourceId,objects);

        this.locations = objects;
        c = context;

        // TODO Auto-generated constructor stub
    }

    public View getView(int position,View convertView,ViewGroup parent){

        View v = convertView;

        if (v == null ){
                    LayoutInflater li = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = li.inflate(R.layout.location_list_item,null);
        }

        Location location = locations.get(position);

        if(location != null){
            TextView locationAddress = (TextView)v.findViewById(R.id.address);
            locationAddress.setText(location.address);

        }

        return v;

    }
}

So, yeah. I’m adding an array list of locations to a listView in a fragment to a tab.

But, no data is showing up. Not a single list. Where am I going wrong?

  • 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-15T11:34:50+00:00Added an answer on June 15, 2026 at 11:34 am

    Have you tried using the fragment’s setListAdapter() function instead of the view’s setAdapter()?

    That is…

    setListAdapter(locationList);
    // instead of ...
    // locationListLayout.setAdapter(locationList);
    

    Oh, and the list view needs to have the id @id/android:list for that to work.

    Edit:

    Is your fragment being shown at all? Try using the provided FT instead of your own one (that’s missing a .commit())

        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) { //*** <-- renamed ft1
            // Check if the fragment is already initialized
    
            // You have no .commit() on this transaction but you should probably use the one passed in, which gets committed for you externally.
            //FragmentManager fragMgr = ((FragmentActivity) mActivity).getSupportFragmentManager();
            //FragmentTransaction ft = fragMgr.beginTransaction();
    
            if (mFragment == null) {
                // If not, instantiate and add it to the activity
                mFragment = Fragment.instantiate(mActivity, mClass.getName());
    
                ft.add(android.R.id.content, mFragment, mTag);
            } else {
                // If it exists, simply attach it in order to show it
                ft.attach(mFragment);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is My main Class public class EndlessAdapterDemo extends Activity { private ListView mListView;
public class HomeActivity extends Activity{ // public ArrayList<User> users1 = new ArrayList<User>(); @Override public
Here's the code: public class MenuTabActivity extends TabActivity implements OnTabChangeListener{ @Override protected void onCreate(Bundle
I don't get my fragment to work... :-( My Activity: public class Test extends
I have a problem: Java Code public class VisualizzaListaActivity extends TabActivity { /** Called
I am using Tab Activity as a main Activity in which it has 4
My program is like this ( main.c ): #include <stdlib.h> #include <stdio.h> void main(){
In the below shown html i have this main div as cxfeeditem feeditem and
I have a GridView like this( main.xml ): <?xml version=1.0 encoding=utf-8?> <GridView xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/gridView1
I've got m2m relationship like this: #main table CREATE TABLE products_product ( id integer

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.