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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:16:11+00:00 2026-06-14T04:16:11+00:00

I have a fragment with 4 tabs, in one tab i need to show

  • 0

I have a fragment with 4 tabs, in one tab i need to show a listview. I have got this far on my code but have a couple errors and i’m not sure if i’m just not doing it right or if i’m missing something simple. Here is my code that i’m using

fragment activity

public class SupportFragment extends SherlockFragment{
String[] supporters = new String[] {
        "Gulf Shores",
        "Central",
        "Spanish Fort",
        "Jackson Heights",
        "Summerdale",
        "Atlas",
        "Robertsdale",
        "Eastern Shore"
};

int[] images = new int[] {
        R.drawable.gulfshores,
        R.drawable.central,
        R.drawable.spanishfort,
        R.drawable.jacksonheights,
        R.drawable.summerdale,
        R.drawable.atlas,
        R.drawable.robertsdale,
        R.drawable.easternshore
};

String[] church = new String[]{
        "Chruch of Christ",
        "Chruch of Christ",
        "Chruch of Christ",
        "Chruch of Christ",
        "Chruch of Christ",
        "Chruch of Christ",
        "Chruch of Christ",
        "Chruch of Christ"
};


 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {

     ViewGroup root = (ViewGroup) inflater.inflate(R.layout.tab_support_layout, null);


     List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();

        for(int i=0;i<10;i++){
            HashMap<String, String> hm = new HashMap<String,String>();
            hm.put("sup", "Supporters : " + supporters[i]);
            hm.put("chur","Church : " + church[i]);
            hm.put("icon", Integer.toString(images[i]) );
            aList.add(hm);
        }

        String[] from = {"sup", "chur", "icon"};

        int[] to = {R.id.icon, R.id.sup, R.id.chur};

        SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.listview_layout, from, to);

        ListView listView = (ListView) findViewById(R.id.listview);

        listView.setAdapter(adapter);


        return root;

 }



 }

I am getting an error on these two lines of code from this

SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.listview_layout, from, to);

and

 ListView listView = (ListView) findViewById(R.id.listview);

the error i’m getting is:

The method getBaseContext() is undefined for the type SupportFragment

The method findViewById(int) is undefined for the type SupportFragment

xml for listview

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

<TextView
    android:id="@+id/textview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
/>

<ListView
    android:id="@+id/listview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
/>
</LinearLayout>

and the listview layout

<?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="horizontal">

<ImageView
    android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingTop="10dp"
    android:paddingRight="10dp"
    android:paddingBottom="10dp"
/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
>
    <TextView
        android:id="@+id/sup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="15dp"
    />

    <TextView
        android:id="@+id/chur"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
    />
</LinearLayout>
</LinearLayout>

any help you can give is greatly appreciated

  • 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-14T04:16:12+00:00Added an answer on June 14, 2026 at 4:16 am

    You do not have a FragmentActivity you have a Fragment, so of course you can’t get the Context with getBaseContext(), you have to use getActivity() instead.
    You also have to inflate a View to use findViewById, if you want to do that in a Fragment. However if you want to use Tabs you need a FragmentActivity which hadels your Fragments.

    You can inflate a View like this in your fragments onCreateView() method:

    View view = inflater.inflate(R.layout.myLayout, null);
    

    Then you can call findViewById like this:

    [...]view.findViewById(...); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Fragment with ImageView . How I can show this Fragment on
I have two tabs using tabhost. One tab having activity extends ExpandableListActivity. It works
I have a FragmentActivity with 2 tabs. Each tab calls a fragment- Calendar and
So I have an FragmentActivity that contains 3 tabs, one tab is essentially a
I have an app with 2 tabs. Each tab has it's respective fragment. On
I have implemented ActionBar Tab in my app. But I am facing one issue
I've got Fragment ActionBar Tabs with an TabListener attached to every tab. In my
I have a simple app (tabs with Fragment contents) obtained by extending this sample:
I have 3 tabs, of which the 1st one has actual data(a listview) and
I have created swipey tabs using ViewPagerExtensions but this time i am using only

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.