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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:03:39+00:00 2026-05-31T16:03:39+00:00

I have a listview, baseadapter and data from SQLite, including a BLOB. What if

  • 0

I have a listview, baseadapter and data from SQLite, including a BLOB. What if the SQL-query changes? (After pressing a button to execute a new SQL-query) I have to use adapter.notifyDataSetChanged

Where can I place that line of code?

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.example);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    placeData = new DatabaseSQL(this);

    String cmd = "select * from plaatjes ";

    Cursor cursors = getRawEvents(cmd);

    if (cursors.moveToNext()) {
        getDataAndPopulate(cmd);
    }

}

private void getDataAndPopulate(String cmd) {
    id = new ArrayList<String>();
    image = new ArrayList<byte[]>();
    caption = new ArrayList<String>();
    description = new ArrayList<String>();
    Cursor cursor = getRawEvents(cmd); 
    while (cursor.moveToNext()) {
        String temp_id = cursor.getString(0);
        byte[] temp_image = cursor.getBlob(1);
        String temp_caption = cursor.getString(2);
        String temp_description = cursor.getString(3);
        id.add(temp_id);
        image.add(temp_image);
        caption.add(temp_caption);
        description.add(temp_description);
    }
    String[] captionArray = (String[]) caption.toArray(
            new String[caption.size()]);

    ItemsAdapter itemsAdapter = new ItemsAdapter(
            Example.this, R.layout.item,
            captionArray);

    setListAdapter(itemsAdapter);

}


private class ItemsAdapter extends BaseAdapter {
    String[] items;

    public ItemsAdapter(Context context, int textViewResourceId,
            String[] items) {
        this.items = items;
    }

    @Override
    public View getView(final int POSITION, View convertView,
            ViewGroup parent) {
        TextView desc;
        TextView cap;
        View view = convertView;
        ImageView img;
        if (view == null) {
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = vi.inflate(R.layout.item, null);

        } 
        img = (ImageView) view.findViewById(R.id.image);
        cap = (TextView) view.findViewById(R.id.caption);
        desc = (TextView) view.findViewById(R.id.description);

        cap.setText(caption.get(POSITION));
        desc.setText(description.get(POSITION));
        img.setImageBitmap(BitmapFactory.decodeByteArray(image.get(POSITION), 0, image.get(POSITION).length));


        return view;
    }

    public int getCount() {
        return items.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
}

private Cursor getRawEvents(String sql) {
    SQLiteDatabase db = (placeData).getReadableDatabase();
    Cursor cursor = db.rawQuery(sql, null);

    startManagingCursor(cursor);
    return cursor;
}

private Cursor getEvents(String table) {
    SQLiteDatabase db = (placeData).getReadableDatabase();
    Cursor cursor = db.query(table, null, null, null, null, null, null);

    startManagingCursor(cursor);
    return cursor;
}

}

  • 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-31T16:03:41+00:00Added an answer on May 31, 2026 at 4:03 pm

    First of all where is the ListView?
    Secondly, don’t put the adapter in the getDataAndPopulate() function. Why are you generating a new adapter everytime?

    Here is the order in which to put them,

    1. ListView
    2. Cursor
    3. Fill the data array [call a function that does it. getDataAndPopulate() ]
    4. Set the data array to the adapter. Make the adapter global in the Activity class file.
    5. Set the adapter to the list.

    In your onClick of the Button
    1. execute the query and fill up the data array.
    2. call adapter.notifyDatasetChanged().

    You ought to use a Cursor Adapter. Would make your life way simpler 😉

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

Sidebar

Related Questions

I have facing problem in listview i am getting data from server and after
i have a listView with a custom BaseAdapter.Every list item has a clickable button.
I have a ListView with an adapter extending BaseAdapter. I create a view (from
I have one ListView and one BaseAdapter.I am downloading Products from webservice and display
HI Guyz i have created a sectioned custom listview using baseadapter its working fine
I have ListView that uses a GridView to display several columns of data. Two
I have ListView which is saving all data to database. For adding i have
I want get data in db to listview. but it have error I cannot
I have an activity which have a button and a listview(with chechbox, image and
When overriding the baseadapter on an android listview, you have to implement this method

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.