0

皆さん。

simplecursorAdapter に問題があります。リストビューをスクロールすると、カスタムレイアウトに含まれる行のお気に入りアイコンが混同され、スクロール中にランダムに表示されることを除いて、すべてが完全に機能します。私のコードの何が問題なのか教えてもらえますか?

前もって感謝します!

public class AlternateRowCursorAdapter extends SimpleCursorAdapter {

int layoutn;
Cursor localCursor, test;
Bitmap bitImg;
Context localContext;
Bitmap Avatar;
ImageView one, two, three, four, five;
LayoutInflater mInflater;
SQLiteDatabase mDb;
MyDbHelper mHelper;

public static final String TABLE_NAME = "MSGS";
public static final String COL_MsgID = "msgIdc";
public static final String COL_MsgCat = "msgCatC";
public static final String COL_MsgTit = "msgtitleC";
public static final String COL_MsgFavor = "msgFavorC";


public AlternateRowCursorAdapter (Context context, int layout, Cursor c,
        String[] from, int[] to) {

    super(context, R.layout.listtype, c, from, to);

    this.localContext = context;

}


@Override
public View getView(int position, View convertView, ViewGroup parent) {


    View row = super.getView(position, convertView, parent);

    final Cursor cursbbn = getCursor();

    if (row == null)

    {
        row = ((LayoutInflater) localContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE))
                .inflate(R.layout.listtype, null);

    }


    final String Title;
    String SandID;
    final String MsgID;
    final String MsgFav;

    Typeface tf = Typeface.createFromAsset(localContext.getAssets(),"fonts/khalaadsara.ttf");

     Title = cursbbn.getString(2);
     SandID = cursbbn.getString(1);
     MsgID=cursbbn.getString(0);
     MsgFav=cursbbn.getString(4);

    TextView titler = (TextView) row.findViewById(R.id.Sandtit);

    titler.setTypeface(tf);
    titler.setText(Title);



    one = (ImageView) row.findViewById(R.id.imageView5);
    two = (ImageView) row.findViewById(R.id.imageView4);
    three = (ImageView) row.findViewById(R.id.ImageView03);
    four = (ImageView) row.findViewById(R.id.ImageView02);
    five = (ImageView) row.findViewById(R.id.imageView1);


    if(MsgFav.contentEquals("YES"))
    {
        one.setImageResource(R.drawable.favorpress);
    }



    return row;

}

}

編集: Onresume イベントの値を更新するコードは次のとおりです。

private void refreshvalues() {

    mDb = mHelper.getWritableDatabase();

    curs = mDb.query(MyDbHelper.TABLE_NAME, columns, null, null, null,
            null, null,

            null);

    cursF = mDb.query(TABLE_NAME, columns, COL_MsgFavor + "=" + "?",
            new String[] { "YES" }, null, null, COL_MsgTit + " ASC");

    String[] headers = new String[] {MyDbHelper.COL_MsgTit ,MyDbHelper.COL_MsgID};

    mAdapter = new AlternateRowCursorAdapter(this, R.layout.listtype, curs,
            headers, new int[] { R.id.Sandtit});

    fAdapter = new AlternateRowCursorAdapter(this, R.layout.listtype,
            cursF, headers, new int[] { R.id.Sandtit });

    mList.setAdapter(mAdapter);
    fList.setAdapter(fAdapter);

curs.moveToFirst();
cursF.moveToFirst();

mAdapter.notifyDataSetChanged();
fAdapter.notifyDataSetChanged();

mList.invalidateViews();
fList.invalidateViews();

curs.requery();
cursF.requery();

}
4

2 に答える 2

0

ListViewViewリスト項目sをリサイクルします。そのため、常に を呼び出すようにしてone.setImageResource()ください。

if (MsgFav.contentEquals("YES")) {
    one.setImageResource(R.drawable.favorpress);
} else {
    one.setImageResource(R.drawable.default_drawable_as_specified_in_layout);
}
于 2013-06-09T01:49:19.920 に答える