Skip to content Skip to sidebar Skip to footer

Images Get Shuffled Or Changed When I Scroll In List View

my images get shuffled or changed when i scroll in list view....... Images get shuffled when i scroll down and keep on changing own its own I have a custom listview adapter, and w

Solution 1:

Okay, no promises as I don't have your complete source code, but these are the modifications I would make to your adapter class:

public class MySimpleArrayAdapter extends BaseAdapter {

    // Rename these to match your database column names
    private static final int SOME_DATABASE_COLUMN_NAME_ZERO = 0;
    private static final int SOME_DATABASE_COLUMN_NAME_THREE = 3;

    private ArrayList<String> mSearchArrayList;
    private Cursor mCursorQuote;

    public MySimpleArrayAdapter(Context context, ArrayList<String> results) {
        mSearchArrayList = results;
        SQLiteDatabase mDatabase = context.openOrCreateDatabase("ORCL", context.MODE_PRIVATE, null);
        mCursorQuote = mDatabase.query("Qotestable", null,
                "Notification_Status" + "=1", null, null, null, "Quote_ID"
                        + "DESC");
    }

    public int getCount() {
        return mSearchArrayList.size();
    }

    public Object getItem(int position) {
        return mSearchArrayList.get(position);
    }

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

    public View getView(int position, View convertView, ViewGroup parent) {
        ArrayList<String> list = new ArrayList<String>();
        ArrayList<String> listid = new ArrayList<String>();
        ViewHolder holder = null;

        if (convertView == null) {
            LayoutInflater li = LayoutInflater.from(parent.getContext());
            convertView = li.inflate(R.layout.homelistvwlyout, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.txtName.setText(mSearchArrayList.get(position));

        if (mCursorQuote.moveToFirst()) {
            do {
                list.add(mCursorQuote.getString(SOME_DATABASE_COLUMN_NAME_THREE)); // no magic values
                listid.add(mCursorQuote.getString(SOME_DATABASE_COLUMN_NAME_ZERO)); // no magic values
            } while (mCursorQuote.moveToNext());
        }
        String s = list.get(position);
        if (s.contentEquals("1")) {
            holder.iv.setImageResource(R.drawable.onestaron);
        } else if (s.contentEquals("2")) {
            holder.iv.setImageResource(R.drawable.twostaron);
        } else if (s.contentEquals("3")) {
            holder.iv.setImageResource(R.drawable.threestaron);
        } else {
            // You need the else-case to set your ImageView --> this is probably your problem
            holder.iv.setImageResource(R.drawable.YOUNEEDSOMETHINGHERE);
        }
        holder.txtvwid.setText(listid.get(position));

        return convertView;
    }

    static class ViewHolder {
        TextView txtName;
        TextView txtvwid;
        ImageView iv;

        /**
         * A constructor that takes a View will encourage the next person to do the right thing with the costly call to
         * findViewById()
         *
         * @param v
         */
        ViewHolder(View v) {
            this.txtName = (TextView) v.findViewById(R.id.textView1);
            this.iv = (ImageView) v.findViewById(R.id.imageView1);
            this.txtvwid = (TextView) v.findViewById(R.id.textView2);
        }
    }
}

Post a Comment for "Images Get Shuffled Or Changed When I Scroll In List View"