Is there a way to set an image on an ImageView inside a ListView ? In this case, I use SimpleCursorAdapter to display all the fields and using the ViewBinder to set the bitmap of the image in the ImageView . Image is uploaded using AsyncTask . The code I wrote is below:
private void updateTimelineUI() { Cursor data = dbHelper.query(Constants.TABLE_NAME, null, null); if (data.moveToFirst()) { adapter = new SimpleCursorAdapter(this, R.layout.tweet_row, data, new String[] {Constants.CREATED_TIME, Constants.USERNAME, Constants.PROFILE_IMAGE, Constants.TWEET}, new int[] {R.id.time, R.id.username, R.id.userImageView, R.id.tweetMessage}); SimpleCursorAdapter.ViewBinder viewBinder = new SimpleCursorAdapter.ViewBinder() { public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if(view != null && view.getId() != R.id.userImageView) { return false; } String imageUrlString = cursor.getString(columnIndex); String username = cursor.getString(cursor.getColumnIndex(Constants.USERNAME)); String path = getDir("images", MODE_PRIVATE).getAbsolutePath() + "/" + username + ".png"; ImageDownloader downloader = new ImageDownloader(); downloader.setImageUrlString(imageUrlString); downloader.setImageView(view); downloader.setFilePath(path); downloader.execute(imageUrlString); return true; } }; int index = data.getColumnIndex(Constants.PROFILE_IMAGE);
Is there a way to set the image to the correct line using this method?
With the code that I have, the images load successfully. However, images are set randomly.
source share