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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:48:27+00:00 2026-06-09T23:48:27+00:00

I am new to programming in Android and I am trying to create an

  • 0

I am new to programming in Android and I am trying to create an app where a user can choose some options from 2 spinners and after tapping on the search button, the app will search through a database based on the options selected and the results will show. The problem is I’m not sure what parameters to put into db.rawQuery to search using the values of the selected spinner options. I have tried to put in a rough guess below, but it is not working and I’m not sure how to make it search using both criteria.

Here is the coding for the spinner:

public class First extends Activity {

private Spinner foodSpinner, locationSpinner;
private Button btnSubmit;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.first);
    addListenerOnButton();
}
public void addListenerOnButton() {

    foodSpinner = (Spinner) findViewById(R.id.foodSpinner);
    locationSpinner = (Spinner) findViewById(R.id.locationSpinner);
    btnSubmit = (Button) findViewById(R.id.btnSubmit);

    btnSubmit.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            Intent intent = new Intent(First.this.getApplicationContext(), MainActivity.class);
            intent.putExtra("FOODSPINNER", foodSpinner.getSelectedItem().toString());
            intent.putExtra("LOCATIONSPINNER", locationSpinner.getSelectedItem().toString());
            First.this.startActivity(intent);

        }

    });

}

Here is the coding for the search:

public class MainActivity extends ListActivity {

    protected SQLiteDatabase db;
    protected Cursor cursor;
    protected ListAdapter adapter;
    protected String foodItemChosen;
    protected String locationItemChosen;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Bundle extras = getIntent().getExtras();
        foodItemChosen = getIntent().getExtras().getString("FOODSPINNER");
        locationItemChosen = extras.getString("LOCATIONSPINNER");
        db = (new DatabaseHelper(this)).getWritableDatabase();
    }


    public void onListItemClick(ListView parent, View view, int position, long id) {
        Intent intent = new Intent(this, ResultDetails.class);
        Cursor cursor = (Cursor) adapter.getItem(position);
        intent.putExtra("FOOD_ID", cursor.getInt(cursor.getColumnIndex("_id")));
        startActivity(intent);
    }

    public void search(View view) {
        cursor = db.rawQuery("SELECT _id, name, address FROM database WHERE food LIKE ?", 
                new String[]{"%" '+foodItemChosen+' "%"});
        adapter = new SimpleCursorAdapter(
                this, 
                R.layout.result_list_item, 
                cursor, 
                new String[] {"name", "address"}, 
                new int[] {R.id.name, R.id.address});
        setListAdapter(adapter);
    }
}
  • 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-09T23:48:29+00:00Added an answer on June 9, 2026 at 11:48 pm

    Then it is better to use query method instead of rawQuery. It provides flexible way to select items from the database.

    Some useful articles

    http://www.vogella.com/articles/AndroidSQLite/article.html

    http://www.codeproject.com/Articles/119293/Using-SQLite-Database-with-Android

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

Sidebar

Related Questions

i am new to android programming and i am trying to develop an app
I am new to android programming and i am trying to develop this app
I'm new in Android Programming. I'm trying to write an app that uses USB
I am new to android programming and trying to build a map activity app.
i'm new to android programming and i'm trying to create a relatively big 2D
I'm trying to learn some Android and java programming in Eclipse. I can run
I'm new to programming for the android and I'm trying to create a simple
I'm trying to make an android app (I'm new in the Android programming world),
I'm fairly new to Android programming. I'm trying to create an animation of a
I'am begginer in android programming and I'am trying to create app that is logging

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.