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

The Archive Base Latest Questions

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

This is my current adapter. This is what i tried to convert the date.

  • 0

This is my current adapter.

This is what i tried to convert the date.

  • 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-10T07:48:41+00:00Added an answer on June 10, 2026 at 7:48 am

    I started changing your adapter to a CursorAdapter but honestly it would be the same as this SimpleCursorAdapter example (I updated it to reflect your code as best I could.):

    public class Example extends Activity {
        SimpleCursorAdapter adapter;
        Database database;
        ListView listView;
    
        @Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            database = new Database(this);
            database.open();
    
            // See my note below for a detailed explanation of this
            Cursor cursor = database.getAllNames();
            adapter = new SimpleCursorAdapter(this,
                    android.R.layout.simple_list_item_checked, 
                    cursor, 
                    new String[] { "name" }, // "name" is the column in your database that I describe below
                    new int[] {android.R.id.text1}, 0);
    
            listView = (ListView) findViewById(R.id.list);
            listView.setAdapter(adapter);
            listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    
            Button delete = (Button) findViewById(R.id.delete_button);
            delete.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    long[] checkedIds = listView.getCheckedItemIds();
                    for(long id : checkedIds)
                        database.deleteName(id);
    
                    listView.clearChoices();
                    adapter.changeCursor(database.getAllNames());
                }
            });
        }
    
        @Override
        protected void onDestroy() {
            database.close();
            super.onDestroy();
        }
    }
    

    Ok, all your need to make this work is a method that returns a Cursor with all of the names (I called it getAllNames()) in your Database class. Now I assumed your table schema looks something like this:

    CREATE TABLE Names (
        _id INTEGER PRIMARY KEY,
        names TEXT);
    

    You can adjust accordingly. Your Database.getAllNames() method should use a query like this:

    "SELECT _id, name FROM Names;"
    

    Or if you want the names alphabetized:

    "SELECT _id, name FROM Names ORDER BY name;"
    

    All together it will look like:

    public Cursor getAllNames() {
        return NameDatabase.rawQuery("SELECT _id, name FROM Names ORDER BY name;", null);
    }
    

    I hope that explains a few things, honestly this is the easiest way to do what you want.


    Adding your own row (list item) layout

    Adding your own layout is simple enough. Since you like the look of simple_list_item_checked.xml, let’s copy it’s layout and tweak it for your colors:

    <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/text1"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/listPreferredItemHeight"
        android:checkMark="?android:attr/textCheckMark"
        android:gravity="center_vertical"
        android:paddingLeft="6dip"
        android:paddingRight="6dip"
        android:textAppearance="?android:attr/textAppearanceLarge" />
    

    All you need to add is:

        android:background="#ffffffff"
        android:textColor="#ff000000"
    

    (Notice that since there is only one element a ViewGroup is not necessary; no LinearLayout, no RelativeLayout, etc. Also "@android:id/text1" is the id that we referenced in the SimpleCursorAdapter `android.R.id.text1′, when you change layouts you need to change these appropriately.)

    However if you only want to invert the colors consider using a different Theme for you entire app. Open up your Manifest and add this theme:

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Light" >
    

    By default Android uses Theme.Dark, simply change it to Theme.Light. Now every item has a white background and black text by default!

    Minor Adjustment to getView()

    For future reference, in your adapter’s getView() you call getLayoutInflater() for every new row. You only need to get the LayoutInflater once in the constructor and save it in a variable, possibly LayoutInflater mLayoutInflater, and use this in getView() with mLayoutInflater.inflate(...).

    Hope that helps!

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

Sidebar

Related Questions

I have the current code: ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item, array_spinner); adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
We have this current database which we need to replace some tables by anther
What is current directory of shell script? Is this current directory from which I
I am having a bit of difficulty with this current code I have set
As a beginner in Ocaml, I have this current working code: ... let ch_in
Like this: Cursor.Current = Cursors.WaitCursor; try { . . . } finally { Cursor.Current
I'm running code that sometimes yields this: UInt32 current; int left, right; ... //sometimes
For some user controls, I have this binding: AppLanguage={Binding Path=ApplicationLanguage, Source={x:Static Application.Current}} This works
How to do it? I don't want to use this: HttpContext.Current.Server.MapPath Is there a
This is my AsyncTask, called from getView of an adapter: class LoadImage extends AsyncTask<Object,Void,String>{

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.