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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:47:31+00:00 2026-05-20T14:47:31+00:00

Hi want to create a custom cursor adapter so I can display an image

  • 0

Hi want to create a custom cursor adapter so I can display an image with 2 lines of text.
I have had some trouble understanding the custom cursor adapters but I do not understand how to add an imageview to be filled from the path in my database.

  • 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-20T14:47:32+00:00Added an answer on May 20, 2026 at 2:47 pm

    Will,

    I’ve actually implemented something incredibly similar to what you are looking for. Here is my implementation.

    import android.content.Context;
    import android.content.SharedPreferences;
    import android.content.res.Resources;
    import android.database.Cursor;
    import android.preference.PreferenceManager;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.CursorAdapter;
    import android.widget.ImageView;
    import android.widget.TextView;
    
    
    public class ItemAdapter extends CursorAdapter {
        private LayoutInflater mLayoutInflater;
        private Context mContext;
        public ItemAdapter(Context context, Cursor c) {
            super(context, c);
            mContext = context;
            mLayoutInflater = LayoutInflater.from(context); 
        }
    
        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            View v = mLayoutInflater.inflate(R.layout.items_row, parent, false);
            return v;
        }
    
        /**
         * @author will
         * 
         * @param   v
         *          The view in which the elements we set up here will be displayed.
         * 
         * @param   context
         *          The running context where this ListView adapter will be active.
         * 
         * @param   c
         *          The Cursor containing the query results we will display.
         */
    
        @Override
        public void bindView(View v, Context context, Cursor c) {
            String title = c.getString(c.getColumnIndexOrThrow(ItemDbAdapter.KEY_TITLE));
            String date = c.getString(c.getColumnIndexOrThrow(ItemDbAdapter.KEY_DATE));
            String imagePath = c.getString(c.getColumnIndexOrThrow(ItemDbAdapter.KEY_IMG));
            int deletion = c.getInt(c.getColumnIndexOrThrow(ItemDbAdapter.KEY_DELETION));
            int priority = c.getInt(c.getColumnIndexOrThrow(ItemDbAdapter.KEY_PRIORITY));
    
            /**
             * Next set the title of the entry.
             */
    
            TextView title_text = (TextView) v.findViewById(R.id.item_text);
            if (title_text != null) {
                title_text.setText(title);
            }
    
            /**
             * Set Date
             */
    
            TextView date_text = (TextView) v.findViewById(R.id.item_date);
            if (date_text != null) {
                date_text.setText(date);
            }       
    
            /**
             * Decide if we should display the paper clip icon denoting image attachment
             */
    
            ImageView item_image = (ImageView) v.findViewById(R.id.item_attachment);
            item_image.setVisibility(ImageView.INVISIBLE);
            if (imagePath != null && imagePath.length() != 0 && item_image != null) {
                item_image.setVisibility(ImageView.VISIBLE);
            }
    
            /**
             * Decide if we should display the deletion indicator
             */
            ImageView del_image = (ImageView) v.findViewById(R.id.item_deletion);
            del_image.setVisibility(ImageView.INVISIBLE);
            if (deletion == 1) {
                del_image.setVisibility(ImageView.VISIBLE);
            }
        }
    }
    

    XML just incase…

    <?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="wrap_content"
        android:orientation="horizontal"
        android:background="@drawable/list_bg">
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
    
            <TextView android:id="@+id/item_text"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:lines="1"
                android:scrollHorizontally="true"
                android:ellipsize="end"
                android:paddingLeft="2sp"
                android:paddingTop="2sp"
                android:textSize="18sp"
                android:textStyle="bold"
                android:shadowColor="#90909090"
                android:shadowDx="1.0"
                android:shadowDy="1.0"
                android:shadowRadius="1.0"/>
    
            <TextView android:id="@+id/item_date"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="12sp"
                android:textColor="#FF808080"
                android:paddingLeft="2sp"
                android:paddingTop="2sp"/>
        </LinearLayout>
    
        <ImageView android:id="@+id/item_deletion"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/deletion"
            android:visibility="invisible"
            android:layout_centerVertical="true"
            android:layout_alignParentRight="true"
            android:paddingRight="5sp"/>
    
        <ImageView android:id="@+id/item_attachment"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/attachment"
            android:visibility="invisible"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@id/item_deletion"/>
    
    </RelativeLayout>
    

    This displays two rows of text and up to 2 images to the right of the text depending on certain conditions.

    I hope this can give you a basis to work from!

    Good luck :]

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

Sidebar

Related Questions

I want to create a custom toolbar control (descendant TToolBar) which should have some
I want to create a custom control in C#. But every time I have
I want to know if i can create a custom google maps application,on which
I want to display a custom image while dragging an object in a drag&drop
I want to create custom objects in C# at runtime, the objects will have
I want to create custom Textbox control in asp.net.But i have one doubt when
I want to create a custom drawable for RadioButton's button drawable. I have created
I want to create a custom MSBuild task that changes my .cs files before
If you want to create a custom attribute for MS test (say [Repeat(3)] how
In C# if I want to create a Custom Event you do something like

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.