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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:10:40+00:00 2026-06-15T22:10:40+00:00

I have an app that uses a tab layout using fragments, in one of

  • 0

I have an app that uses a tab layout using fragments, in one of the fragments I would like to have a two/multi-line List View, I have been following this tutorial which shows it for a ListActivity. I have copied the code into my fragment and cannot seem to get it to work. all of my code for the layout of the fragment and the two lines is the same as code in the link above, with the exception of the Java class for the fragment I want to show the list in.

The code for the fragment is as follows:

package com.example.shopsellswap;

import java.util.ArrayList;
import java.util.HashMap;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;

public class Fragment_My_Profile extends ListFragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View myProfileView = inflater.inflate(R.layout.fragment_my_profile, container, false);


        return myProfileView;
    }

    //ArrayList holds the data (as HashMaps) to load into the ListView
        ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
        //SimpleAdapter does the work to load the data in to the ListView
        private SimpleAdapter sa;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            //HashMap links each line of data to the correct TextView
            HashMap<String,String> item;
            for(int i=0;i<StatesAndCapitals.length;i++){
              item = new HashMap<String,String>();
              item.put( "line1", StatesAndCapitals[i][0]);
              item.put( "line2", StatesAndCapitals[i][3]);
              list.add( item );
            }

            sa = new SimpleAdapter(Fragment_My_Profile.this, list,
                    R.layout.my_two_lines,
                    new String[] { "line1","line2" },
                    new int[] {R.id.line_a, R.id.line_b});

            setListAdapter(sa);
        }

        private String[][] StatesAndCapitals =
            {{"Alabama","Montgomery"},
            {"Alaska","Juneau"},
            {"Arizona","Phoenix"},
            {"Arkansas","Little Rock"},
            {"California","Sacramento"}};

The part that is giving me errors is

        sa = new SimpleAdapter(Fragment_My_Profile.this, list,
                R.layout.my_two_lines,
                new String[] { "line1","line2" },
                new int[] {R.id.line_a, R.id.line_b});

        setListAdapter(sa);

the specific error is:

The constructor SimpleAdapter(Fragment_My_Profile, ArrayList<HashMap<String,String>>, int, String[], int[]) is undefined

what’s weird is when I change ListFragment to ListActivity the error is no longer there

Why it isn’t working and how I can fix it?

  • 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-15T22:10:42+00:00Added an answer on June 15, 2026 at 10:10 pm

    ListFragment is not a subclass of Context, while ListActivity is. You must pass some type of Context to this constructor. For example, let’s assume that your Activity (or FragmentActivity) class is named MainActivity:

    sa = new SimpleAdapter(MainActivity.this, list, ...
    

    Depending on when you create this Fragment that might not work, so you can move all of your code in onCreate() to the onActivityCreated() method and use:

    sa = new SimpleAdapter(getActivity(), list, ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have app that uses two threads: one thread for regular application work and
I have an Android App that uses a TabHost layout. Every tab calls the
I have an app that uses the ActionBar with tabs in combination with Fragments.
I have an app that uses Apples reachability code. When I tab out of
I'm currently programming an app for iphone that uses the tab bar. One of
I have an app that uses ActionBarSherlock to provide a ViewPager control for tab
I have an app that uses fragments, its working ok, but I have now
I have an app that uses a tab bar controller. It has five tabs.
I have an Android App that uses TabWidgets for displaying 4 Tabs. Each Tab
I have an iPhone app (in XCode 4) that uses the standard Tab Bar

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.