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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:47:48+00:00 2026-06-10T15:47:48+00:00

I have a activity that fills a ListView, and it is working. Because I

  • 0

I have a activity that fills a ListView, and it is working. Because I use a tabs ViewPager, I have to use fragments instead of activities. So can somebody tell me what I need to change to make a fragment from my activity (FragmentActivity cannot be used in tabs).

package com.basnijkamp.safanagendatest;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class ListSample extends Activity {  

    public final static String ITEM_TITLE = "title";  
    public final static String ITEM_CAPTION = "caption";  

    public Map<String,?> createItem(String title, String caption) {  
        Map<String,String> item = new HashMap<String,String>();  
        item.put(ITEM_TITLE, title);  
        item.put(ITEM_CAPTION, caption);  
        return item;  
    }  

    @Override  
    public void onCreate(Bundle icicle) {  
        super.onCreate(icicle);  

        List<Map<String,?>> september2012 = new LinkedList<Map<String,?>>();  
        september2012.add(createItem("Electra Mining Africa 2012", "Johannesberg South Africa"));  
        september2012.add(createItem("MSV", "Brno Czech Republic"));  
        september2012.add(createItem("IMTS", "Chicago USA"));
        september2012.add(createItem("AMB", "Stuttgart Germany"));  
        september2012.add(createItem("Den Teknise Messe", "Lillestrom Norway"));  
        september2012.add(createItem("ITM", "Plovdiv Bulgaria"));  

        List<Map<String,?>> oktober2012 = new LinkedList<Map<String,?>>();  
        oktober2012.add(createItem("BIMU", "Milan Italy"));  
        oktober2012.add(createItem("Matek", "Istanbul"));
        oktober2012.add(createItem("TIB", "Bucharest Romania"));
        oktober2012.add(createItem("Vienna Tec", "Vienna Austria"));
        oktober2012.add(createItem("Euro Blech 2012", "Hanover Germany"));
        oktober2012.add(createItem("Technica Massan", "Stockholm Sweden"));

        List<Map<String,?>> november2012 = new LinkedList<Map<String,?>>();  
        november2012.add(createItem("JIMTOF", "Tokyo Japan"));
        november2012.add(createItem("Metavak", "Gorinchem Netherlands"));
        november2012.add(createItem("FABTECH", "Las Vegas USA"));
        november2012.add(createItem("Prodex", "Basel Switzerland"));
        november2012.add(createItem("EMAF 2012", "Porto Portugal"));
        november2012.add(createItem("Manufact Indonesia", "Jakarta Indonesia"));

        // create our list and custom adapter  
        SeparatedListAdapter adapter = new SeparatedListAdapter(this);  
        adapter.addSection("September 2012", new SimpleAdapter(this, september2012, R.layout.list_complex,   
            new String[] { ITEM_TITLE, ITEM_CAPTION }, new int[] { R.id.list_complex_title, R.id.list_complex_caption }));
        adapter.addSection("Oktober 2012", new SimpleAdapter(this, oktober2012, R.layout.list_complex,   
            new String[] { ITEM_TITLE, ITEM_CAPTION }, new int[] { R.id.list_complex_title, R.id.list_complex_caption }));
        adapter.addSection("November 2012", new SimpleAdapter(this, november2012, R.layout.list_complex,   
                new String[] { ITEM_TITLE, ITEM_CAPTION }, new int[] { R.id.list_complex_title, R.id.list_complex_caption }));

        ListView list = new ListView(this);  
        list.setAdapter(adapter);  
        this.setContentView(list);  

    }  

}  

Thanks in advance

  • 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-10T15:47:50+00:00Added an answer on June 10, 2026 at 3:47 pm

    I would recommend you to extends ListFragment – http://developer.android.com/reference/android/app/ListFragment.html .

    So from this:

            ListView list = new ListView(this); 
            list.setAdapter(adapter); 
            this.setContentView(list); 
    

    you should do this:

            setListAdapter (adapter); 
    

    from

    @Override 
    public void onCreate(Bundle icicle) { 
            super.onCreate(icicle);
    

    ->

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    

    and from ListSample extends Activity -> ListSample extends ListFragment

    Let me know if more details needed, good luck

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

Sidebar

Related Questions

I have an Activity that should only get created once. That is, onCreate can
I have an activity that extends ListView. I populate my list with the results
I have a TabHost activity that are switching activities, so my main looks like
I have xml listview. How I can change its height in activity? I know
I have created a listview that sits inside a larger activity (the list view
I have an ArrayAdapter that I use to fill a listview, but I'm unable
I am having the following problem: In my Activity, I have a listview that
I have an activity that opens txt files. And everytime a user wants to
I have an activity that when users press share on a file it would
I have an activity that shows some TextView s and EditText s, as well

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.