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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:35:52+00:00 2026-06-03T09:35:52+00:00

i have cursor which selects records from my CarProfile table and use custom adapter

  • 0

i have cursor which selects records from my CarProfile table and use custom adapter to show
brand, model and the linenceplate in the spinner selection. my problem is that i want to have selection which says “ALL” for a first item, so if chosen i could display information for all the cars. my code is:

            // spinner 1
        mDbAdapter.open();
        Cursor cursorCP = mDbAdapter.fetchAllProfiles();
        startManagingCursor(cursorCP);
        mDbAdapter.close();

        MyCustomAdapter ad = new MyCustomAdapter(this, cursorCP);
        spinCP.setAdapter(ad);

    public class MyCustomAdapter extends CursorAdapter {

    public MyCustomAdapter(Context context, Cursor c) {
        super(context, c);

    }
    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        TextView nameTextView = (TextView) view
                .findViewById(android.R.id.text1);

        String brand = cursor.getString(cursor
                .getColumnIndex(DefaxedDbAdapter.KEY_BRAND));
        String model = cursor.getString(cursor
                .getColumnIndex(DefaxedDbAdapter.KEY_MODEL));
        String licence = cursor.getString(cursor
                .getColumnIndex(DefaxedDbAdapter.KEY_LICENCEPLATE));
        nameTextView.setText(brand + "-" + model + "-" + licence);
    }
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        View view = View.inflate(context,
                android.R.layout.simple_spinner_dropdown_item, null);
        return view;

    }
}
  • 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-03T09:35:53+00:00Added an answer on June 3, 2026 at 9:35 am

    ok my fix at the end was to use array adapter with the help of hashmap to store the id’s. here is the code i used

            ArrayList<String> arr = new ArrayList<String>();
        arr.add(DefaxedDbAdapter.ALL_LABEL);
    
        hm = new HashMap<String, Integer>();
    
        while (!cursorProfiles.isAfterLast()) {
            int rowId = cursorProfiles.getInt(cursorProfiles
                    .getColumnIndex(DefaxedDbAdapter.KEY_ROWID));
            String brand = cursorProfiles.getString(cursorProfiles
                    .getColumnIndex(DefaxedDbAdapter.KEY_BRAND));
            String model = cursorProfiles.getString(cursorProfiles
                    .getColumnIndex(DefaxedDbAdapter.KEY_MODEL));
            String licencePlate = cursorProfiles.getString(cursorProfiles
                    .getColumnIndex(DefaxedDbAdapter.KEY_LICENCEPLATE));
            arr.add(brand + "-" + model + "-" + licencePlate);
            hm.put(brand + "-" + model + "-" + licencePlate, rowId);
            cursorProfiles.moveToNext();
        }
    
        ArrayAdapter<String> adapterProfiles = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_dropdown_item, arr);
        profilesSpinner.setAdapter(adapterProfiles);
    

    and then after selecting an item from spinner you can get the id like that

                    if (profilesSpinner.getSelectedItemId() != 0) {
    
                    String tmp = profilesSpinner.getSelectedItem().toString();
                    carId = hm.get(tmp);
    
                    if (alreadySet) {
                        SQLquery += " AND expenses.carId =" + carId;
                    } else {
                        SQLquery += " WHERE expenses.carId =" + carId;
                    }
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Django Model which retrieves 3 records from a database. The
I have a table from which I have to fetch around 7 million records,
I have some trouble when trying to update a table by looping cursor which
I have a cursor which returns two values: one which I will use (and
Possible Duplicate: SQL - find records from one table which don't exist in another
I am creating a Control Library project. I have some Cursor files which i
I have a stored procedure which returns a ref cursor as follows: CREATE OR
If I have a function which returns a reference cursor for a query, how
I have the cursor with the query statement as follows: cursor.execute(select rowid from components
I have obtained the crosshair cursor from NSCursor crosshairCursor. Then, how can i change

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.