Note that there are some explanatory texts on larger screens.

plurals
  1. PORepeated items in the ListView (photos)
    primarykey
    data
    text
    <p>i'm building small sms-like application. I made conversation list view, but there is a problem. Every row in the list has photo (contact photo) and if i scroll down some rows have photos from different rows (from the beggining of the list).</p> <p>Here's my adapter:</p> <pre><code>import android.content.ContentResolver; import android.content.Context; import android.database.Cursor; import android.graphics.Bitmap; import android.text.format.DateUtils; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.SimpleCursorAdapter; import android.widget.TextView; public class ConversationAdapter extends SimpleCursorAdapter { private final String TAG = "ConversationAdapter"; static final String[] FROM = {"body", "address", "date", "m_size"}; static final int[] TO = {R.id.textMsg, R.id.textPerson, R.id.textDate, R.id.textConvCounter}; ImageView imageAvatar; ContentResolver contentResolver; LayoutInflater layoutInflater; public ConversationAdapter(Context context, Cursor c) { super(context, R.layout.row, c, FROM, TO); } @Override public void bindView(View row, Context context, Cursor cursor) { super.bindView(row, context, cursor); long timestamp = cursor.getLong(cursor.getColumnIndex("date")); TextView textDate = (TextView) row.findViewById(R.id.textDate); textDate.setText(DateUtils.getRelativeTimeSpanString(timestamp)); TextView textMsg = (TextView) row.findViewById(R.id.textMsg); String previewMsg = cursor.getString(cursor.getColumnIndex("body")); if (previewMsg.length() &gt; 40) { textMsg.setText(previewMsg.substring(0, 37) + "..."); } TextView textPerson = (TextView) row.findViewById(R.id.textPerson); String contactId = DataManager.getContactId(context, (textPerson.getText()).toString()); if (contactId != "") { contentResolver = context.getContentResolver(); imageAvatar = (ImageView) row.findViewById(R.id.imageAvatar); Long lContactId = Long.parseLong(contactId); Bitmap bitmap = DataManager.getContactPhoto(contentResolver, lContactId); if (bitmap != null) { imageAvatar.setImageBitmap(bitmap); bitmap = null; } String contactName = DataManager.getContactName(context, (textPerson.getText()).toString()); textPerson.setText(contactName); } } } </code></pre> <p>and there is my activity that shows the list:</p> <pre><code>import android.app.Activity; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; public class ConversationsActivity extends Activity { private final String TAG = "ConversationsActivity"; ConversationAdapter adapter; ContentResolver contentResolver; Cursor cursor; ListView convList; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.conversations_list); convList = (ListView) findViewById(R.id.convList); } @Override protected void onResume() { super.onResume(); setupConvsList(); } void setupConvsList() { Context context = getApplicationContext(); contentResolver = context.getContentResolver(); cursor = contentResolver.query(Uri.parse("content://mms-sms/conversations"), null, null, null, "date DESC"); startManagingCursor(cursor); adapter = new ConversationAdapter(this, cursor); convList.setAdapter(adapter); } } </code></pre> <p>What do i have to change? Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload