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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:50:13+00:00 2026-05-26T01:50:13+00:00

I need a little help with my custom list view adapter. I’m using the

  • 0

I need a little help with my custom list view adapter. I’m using the adapter example from vogella.de, but I need to find a way how to set text and image from sqlite database. Here is the adapter code which I am using :

import android.app.Activity;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyArrayAdapter extends ArrayAdapter<String> {
    private final Activity context;
    private final String[] names;
    Cursor cursor;

    public MyArrayAdapter(Activity context, String[] names) {
        super(context, R.layout.main_listview, names);
        this.context = context;
        this.names = names;
    }

    // static to save the reference to the outer class and to avoid access to
    // any members of the containing class
    static class ViewHolder {
        public ImageView imageView;
        public TextView textView,textView2;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // ViewHolder will buffer the assess to the individual fields of the row
        // layout

        ViewHolder holder;
        // Recycle existing view if passed as parameter
        // This will save memory and time on Android
        // This only works if the base layout for all classes are the same
        View rowView = convertView;
        if (rowView == null) {

            LayoutInflater inflater = context.getLayoutInflater();
            rowView = inflater.inflate(R.layout.main_listview, null, true);

            holder = new ViewHolder();
            holder.textView = (TextView) rowView.findViewById(R.id.main_name);
            holder.textView2 = (TextView) rowView.findViewById(R.id.main_info);
            holder.imageView = (ImageView) rowView.findViewById(R.id.main_img);
            rowView.setTag(holder);

        } else {
            holder = (ViewHolder) rowView.getTag();
        }
        final Bitmap b = BitmapFactory.decodeFile("/sdcard/52dde26940e0d3081f6a086d4b54cd1c.jpg", null);

        holder.textView.setText("");
        holder.textView2.setText("");
        holder.imageView.setImageBitmap(b);


        return rowView;
    }

    public String[] getNames() {
        return names;
    }
}

And I’m trying to set the text to a text view like this :

 String sql = "SELECT title FROM collections";
        Cursor cursorTitle = userDbHelper.executeSQLQuery(sql);
        if(cursorTitle.getCount()==0){
            Log.i("Cursor Null","CURSOR TITLE NULL");
        } else if(cursorTitle.getCount()>0){
            cursorTitle.moveToFirst();
            String text = cursorTitle.getString(cursorTitle.getColumnIndex("title"));
            Log.i("title text","title text : "+text);
            String[] names = new String[] { text };
            listView.setAdapter(new MyArrayAdapter(this, names));
 }

,but when I run that code I don’t get anything in my listview as a result.

So can anyone suggest me how can I set the text and image in imageview and textview in my activity using this adapter.

Thanks a lot!

  • 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-26T01:50:13+00:00Added an answer on May 26, 2026 at 1:50 am

    Try to do something like this :

    MyAddapterClass :

        private final Activity context;
        private final String[] names;
        private final Bitmap image;
        private final String text;
        private final String text2;
        Cursor cursor;
    
        public MyArrayAdapter(Activity context, String[] names, Bitmap image, String text, String text2) {
            super(context, R.layout.main_listview, names);
            this.context = context;
            this.names = names;
            this.image = image;
            this.text = text;
            this.text2 = text2;
        }
    

    and set image, text and text2 to your holders :

        holder.textView.setText(text);
        holder.textView2.setText(text2);
        holder.imageView.setImageBitmap(image);
    

    and initialize it in your Activity.That’s it.

    Hope it helps!

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

Sidebar

Related Questions

I need a little help on this subject. I have a Web application written
I am getting a little confused and need some help please. Take these two
I need to build a little webapp but I'm not sure what is the
I know a little about SNMP, but not enough. I need to develop an
I've used both SVN and CVS a little bit, but will need to choose
Need a way to allow sorting except for last item with in a list.
I have started to study UML standard and would need little help with two
Need a little help with string formatting... I have a string like this: Bmw
I need a little help if someone's got a minute. I've written a web
I'm a PHP programmer by default, and I need a little help with a

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.