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

  • Home
  • SEARCH
  • 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 3624036
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:27:27+00:00 2026-05-18T23:27:27+00:00

I have a listview which loads its data from sqlite database. Each row in

  • 0

I have a listview which loads its data from sqlite database.
Each row in listview has image , textview and a checkbox.
The sqlitedatabase rows has image and text data + some other columns.

My question is can I bind my listview with the database so that all rows will be loaded with required data automatically. (image + textview) There are examples to bind a simple list of textviews. What about complex rows ? Also there are few spinners which can filter the data in list depending on its value. (Which act as a WHERE clause on my DB)

Currently I am managing this all by generating the view for my custom adapter for each row. So each time I query database and populate data. I hold the last listview results , make a newer results based on actions/conditions like spinner values, then notifydatachanged to adapter to load my new results.

To add features like DELETE , ADD , SEARCH — I have to manage it all using collections.

Is there any simple way of doing this ? As if the db is large then the approach of holding such huge set of results in memory is not good. And is painful for managing it.
Thanks.

  • 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-18T23:27:28+00:00Added an answer on May 18, 2026 at 11:27 pm

    Here is my example for row, constructed from two records from db + image (at current – one image for any row, but it can be improved for specific image from db):

        public class DomainAdapter extends SimpleCursorAdapter{
        private Cursor dataCursor;
    
        private LayoutInflater mInflater;
        ....
    
        public DomainAdapter(Context context, int layout, Cursor dataCursor, String[] from,
                int[] to) {
            super(context, layout, dataCursor, from, to);
                this.dataCursor = dataCursor;
                mInflater = LayoutInflater.from(context);
        }
    
        public View getView(int position, View convertView, ViewGroup parent) {
            // A ViewHolder keeps references to children views to avoid unneccessary calls
            // to findViewById() on each row.
            ViewHolder holder;
    
            // When convertView is not null, we can reuse it directly, there is no need
            // to reinflate it. We only inflate a new View when the convertView supplied
            // by ListView is null.
            if (convertView == null) {
                convertView = mInflater.inflate(layout, null);
    
                // Creates a ViewHolder and store references to the two children views
                // we want to bind data to.
                holder = new ViewHolder();
                holder.text1 = (TextView) convertView.findViewById(R.id.test_track);
                holder.text2 = (TextView) convertView.findViewById(R.id.test_band);
                holder.icon = (ImageView) convertView.findViewById(R.id.test_artwork);
    
                convertView.setTag(holder);
            } else {
                // Get the ViewHolder back to get fast access to the TextView
                // and the ImageView.
                holder = (ViewHolder) convertView.getTag();
            }
    
            // Bind the data efficiently with the holder.
            // Cursor to current item
            dataCursor.moveToPosition(position);
            int title_index = dataCursor.getColumnIndex(fields[0]); 
            String title = dataCursor.getString(title_index);
    
            int description_index = dataCursor.getColumnIndex(fields[1]); 
            String description = dataCursor.getString(description_index);
    
            holder.text1.setText(title);
            holder.text2.setText(description);
            holder.icon.setImageResource(R.drawable.alert_dialog_icon);
    
            return convertView;
        }
    
        static class ViewHolder {
            TextView text1;
            TextView text2;
            ImageView icon;
        }
    }
    

    and using this adapter:

    databaseListAdapter = new DomainAdapter(this, 
                    R.layout.test_layout, 
                    databaseCursor, 
                    new String[] {"title", "description"}, 
                    new int[] { R.id.test_track, R.id.test_track });
    databaseListAdapter.notifyDataSetChanged();
    DomainView.setAdapter(databaseListAdapter);
    

    and layout:

    <?xml version="1.0" encoding="utf-8"?>
    
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="64dip"
        android:padding="6dip">
    
        <TextView
            android:id="@+id/test_band"  
            android:layout_width="fill_parent" 
            android:layout_height="26dip" 
    
            android:layout_below="@+id/test_track"
            android:layout_alignLeft="@id/test_track"
            android:layout_alignParentBottom="true"
    
            android:gravity="top" />
    
        <TextView
            android:id="@id/test_track"  
            android:layout_marginLeft="6dip"
            android:layout_width="fill_parent"
            android:layout_height="26dip"
    
            android:layout_toRightOf="@+id/test_artwork"
    
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:gravity="bottom" />
    
        <ImageView
            android:id="@id/test_artwork"
            android:layout_width="56dip"
            android:layout_height="56dip"
            android:layout_gravity="center_vertical" />
    
    </RelativeLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF ListView which repeats the data vertically. I cannot figure out
I currently have a list view which has several rows of data and I
I have found this example Lazy load of images in ListView from Fedor which
I have found this example Lazy load of images in ListView from Fedor which
I have a ListView which sometimes I need to put around 10000 items in.
I have an app with a large ListView which is terribly slow so I'm
I have a ListView control which is exhibiting an odd behaviour - rows are
When my ListView activity loads it creates the Adapter which fills the screen as
I have a listview which I would like to fill with self created user
I have a list view control which at the moment only allows one item

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.