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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:02:41+00:00 2026-06-13T05:02:41+00:00

I have a simple (?) Android application that begins with an Activity (First Activity)

  • 0

I have a simple (?) Android application that begins with an Activity (“First Activity”) with a ListView that lists three items: Beginning, Intermediate and Advanced. So far, so good. What I want to happen next is if the user clicks on e.g. Beginning, a SQLite database will be queried and all items designated “Beginning” in the database will be retrieved. I then want a second Activity (“Second Activity”) to launch and have all the items from the query displayed in a ListView on that Activity. I have this working using a cursor, but I’m trying to update my code to use a LoaderManager and a CursorLoader. I think that I need to put an onCreateLoader method inside the ListView’s onItemClick method in the First Activity. To give an example, I’m thinking of code like this:

public class FirstActivity extends ListActivity implements LoaderManager.LoaderCallbacks<Cursor> {
    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ListView listview = getListView();
    String[] values = new String[] {
            "Beginning", "Intermediate", "Advanced"
    };

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, values);
    listview.setAdapter(adapter);

    listview.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    return new CursorLoader(this, <myUri>,
            <myFields>, <myQuery>, null, null); 
}               
        }

    });
}

}

Also in my onClickItem, I’m going to create an Intent and stuff it with a Bundle of data (my Second Activity’s ListView will need this data for its onItemClick method). Anyway, when I try this, Eclipse is unhappy with the onCreateLoader inside the onItemClick, giving me lots of error messages about mismatched curly braces, missing semi-colons, etc. So what am I doing wrong? How do I query my database when a listitem is clicked? If I move the onCreateLoader method outside of the onItemClick method, but within the setItemClickListener, I don’t get error messages, but then how do I reference it within my onItemClick method?

Any help is greatly appreciated. Many thanks in advance!


Thanks very much for both answers! I’m an Android newbie; I’m trying to implement your suggestions and am stuck once again. I created a new Activity called GetLevelData. My first activity now looks like this:

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

    ListView listview = getListView();
    final String[] values = new String[] {
            "Beginning", "Intermediate", "Advanced"
    };

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, values);
    listview.setAdapter(adapter);

    listview.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            Intent choice = new Intent(getApplicationContext(), com.MyProject.project.GetLevelData.class);
            Bundle dataBundle = new Bundle();
            String chosenValue = values[position];
            dataBundle.putString("Level",chosenValue);
            choice.putExtras(dataBundle);
            try {
                startActivity(choice);
            } catch (Exception e) {
                Dialog d = new Dialog(getApplicationContext());
                d.setTitle("MyProjectActivity line 60");
                TextView tv = new TextView(getApplicationContext());
                tv.setText(e.toString());
                d.setContentView(tv);
                d.show();
            } finally {

            }
        }

    });
}

My new Activity looks like this:

public class GetLevelData extends Activity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.leveldata);

    Intent myData = getIntent();
    Bundle info = myData.getExtras();

    if (info != null){
        TextView myTextView = (TextView)findViewById(R.id.textView1);
        String level = info.getString("Level");
        myTextView.setText(level);
    }
}

}

textView1 is a TextView inside a LinearLayout in leveldata.xml in my layout folder. When I try to run this, at startActivity, I get an exception: Activity not found. What am I missing? I’

  • 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-13T05:02:42+00:00Added an answer on June 13, 2026 at 5:02 am

    To make it simpler pass the choice to the second activity, not the cursor. Also CursorLoader is for content handlers not for general cursors. Last time I did something like this I believe I inherited AsyncTaskLoader.

    Thus, pass the choice in an extra in the intent, and let the second activity do the query.

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

Sidebar

Related Questions

I'm writing my first Android application and I have one activity that I'd like
I have a simple Android application that has an Activity with an Observable object,
I have a simple Android application that uses a JAR I have built. When
I'm developing a simple Android application that would have an action bar on the
So I have a very simple android activity that starts a timer when you
I have a simple Android native java application that reads data from a Bluetooth
I'm writing a simple application that uses sockets . I have an activity that
I have written a simple Android application that uses a sqlite database which is
i have an android application which has a listview for listing 14 items inside
I have a simple application that has 3 activities. The third activity is a

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.