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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:07:25+00:00 2026-05-17T19:07:25+00:00

I am creating an android application in which there are two activites. One activity

  • 0

I am creating an android application in which there are two activites. One activity contains a button. On the button click, i want to switch to other activity which displays a list view containing few options.

Two switch between the screens or activities , i am using the following code

Intent intent = new Intent(Activity1.this,Activity2.class);
               startActivity(intent);

Since my Activity2 class extends the ‘ListActivity’, this code doesn’t seem to work. On my button click, i want to display a list view containing some data.

Any help would be appreciated

@Siddharth
i seem to be doing almost the same thing
Here is my actual code

From Activity 1

public void onClick(View v) {

            Intent intent = new Intent(View_Data.this,CategoryList.class);
               startActivity(intent);

        }

In Activity 2

public class CategoryList extends ListActivity {

public TextView selection;
public String[] categories;
ArrayList<String> type_of_category;


protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.category_list);
    getCategories();    

}

    public void getCategories() {

        DBHelper dbhelper = new DBHelper(this);
        type_of_category = new ArrayList<String>();

        type_of_category = dbhelper.getTypesOfQuotes();
        String[] items = new String[100];
        for(int i=0;i<type_of_type_of_category.size();i++)
        {
            items[i] = type_of_type_of_category.get(i);
        }

        setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,items));

    }

}

Here is my XML File

   <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/hello" />

</LinearLayout>

In My 2nd Activity, i get the error in this line

 setContentView(R.layout.category_list);
  • 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-05-17T19:07:26+00:00Added an answer on May 17, 2026 at 7:07 pm

    Depending on whether your data in the second activity is from a database or static data, this code should work for you. I am assuming from your post that you dont need to send data from the 1st activity to the 2nd activity. This is actual code from my application which is database driven. If you are not using a database, parts of this code can be changed to use that instead of a database. It should get you started:

    From the 1st Activity:

    public void onClickListContacts(View target)
    {
        Intent listContacts = new Intent(this, com.dzinesunlimited.quotetogo.ContactsList.class);
        startActivity(listContacts);
    }
    

    The 2nd activity:

    public class ContactsList extends ListActivity {
    DBAdapter dbContactList;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.contacts_list);
    
        dbContactList = new DBAdapter(this);
    
        // Calls the method to display the ListView of all Contacts
        fillData();
    }    
    
    private void fillData() {
        // Pull the data from the database
        String[] fields = new String[]    {    dbContactList.TABLE_CON_NAME    };
        int[] views = new int[]    {    android.R.id.text1    };
    
        Cursor c = dbContactList.getAllContacts();
        startManagingCursor(c);
    
        // Set the ListView
        ListAdapter prjName = new SimpleCursorAdapter(this,
                android.R.layout.simple_list_item_1, c, fields, views);
        setListAdapter(prjName);
    
        dbContactList.close();
    
    }
    

    For a static list, you can also refer to this tutorial: http://www.vogella.de/articles/Android/article.html#lists

    Hope this helps.

    PS: It would be great help if you could post code of the 2nd activity which has problems.

    Add this to your XML and see if that helps:

    <ListView 
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"    >
    </ListView>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use a custom font for my android application which I am
I am creating a multiple stop watch application for which there will be multiple
Currently I am working on an Android application that is dynamically creating controls. Everytime
I've been assigned to create an RESTful Android application for an existing web service
I am trying to use the Jets3t library within an Android application, and I
I am using the Android Emulator to debug my application, first off it is
I am contemplating creating a realtime app where an iPod Touch/iPhone/iPad talks to a
What Windows Phone 7 demo/reference applications have you seen which really made you interested
I'm trying to open a dialog window, but every time I try to open
I've scoured over the questions here, but cannot seem to find an answer, so

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.