1

im trying to refresh my listview after i deleted a row from SQLite DB. This is part of it:

cursor = mysqlAdapter.fetchAll(); // a method from sqlite adater class 
ArrayList<MyInfo> vidRows = new ArrayList<MyInfo>(); 
if (cursor.moveToFirst()) { 
do { ...... } 
while (cursor.moveToNext()); } 
mList.setAdapter(new SomeAdapter(this, vidRows)); 
mList.setOnItemClickListener(this); 
registerForContextMenu(mList); } 

Then in my getView i do:

public View getView(int position, View convertView, ViewGroup parent) { 
View vidRow = inflater.inflate(R.layout.queue_row, null); 
ImageView vidThumb = (ImageView) vidRow .findViewById(R.id.Thumb); 
Bitmap bmThumbnail; bmThumbnail = ThumbnailUtils.createVideoThumbnail(
                     getFullpath(vidItems.get(position).my_id), Thumbnails.MINI_KIND);      
vidThumb.setImageBitmap(bmThumbnail); 
TextView vidText = (TextView) vidRow .findViewById(R.id.vid_cap);
videoText.setText(vidItems.get(position).my_cap); return vidRow; } 

3 Answers 3

1

Are you using a cursor? If so you can just call:

cursor.requery();
Sign up to request clarification or add additional context in comments.

7 Comments

That comes with a few caveats, but it works.
fair nuff. I have used it in the past for a delete only, but for sorting or anything else I request a new cursor.
i am using cursor to query the DB. I have tried cursor.requery() but it doesnt work.
I know you're using a cursor to query the DB but I don't know how you're populating your listview, SimpleCursorAdapter? If so then after you delete your row, you call requery it should work.
Can you update your question with this code (formatted) and I will update my answer.
|
0

Are you using a list to populate your ListView? I would prefer doing it manually like this -

myList.remove(delPos);
getListView().invalidateViews();

2 Comments

no i am not using a list...im using cursor with DB and some images from a folder. Anyone.....?
I saw your code above in the comments. You are using vidRows to populate your list. This code should work for you.
0

I know this is kinda old but I'll reply in case anyone else have the same issue and it can help.

You could use a cursor adapter and pass the cursor to it using swapCursor (also works when using onCursorLoader) then whenever you delete a row you could do one of the follow:

  1. delete a row from your db outside of the adapter and then call adapter.notifyDataSetChanged()

or

  1. embed the db inside your adapter and create a delete method so when you call adapter.delete() is updates both the list (if you still use it) and the db.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.