本文介绍了图像获得洗牌或更改,当我在列表视图滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的图片得到洗牌或当我在列表视图滚动改变.......当我向下滚动,不断改变自己的自己的我有一个自定义列表视图适配器和图像获得洗牌,当我向下滚动/向上列表,图像获得洗牌,我不知道该怎么办。

 公共类MySimpleArrayAdapter延伸BaseAdapter {
     私有静态的ArrayList<串GT; sea​​rchArrayList;
     SQLiteDatabase数据库;
     私人LayoutInflater mInflater;
     ArrayList的<串GT;名单=新的ArrayList<串GT;();
     ArrayList的<串GT; listid =新的ArrayList<串GT;();     公共MySimpleArrayAdapter(上下文的背景下,ArrayList的<串GT;业绩){
      sea​​rchArrayList =结果;
      mInflater = LayoutInflater.from(上下文);
      数据库= context.openOrCreateDatabase(ORCL,context.MODE_PRIVATE,NULL);
     }     公众诠释的getCount(){
      返回searchArrayList.size();
     }     公共对象的getItem(INT位置){
      返回searchArrayList.get(位置);
     }     众长getItemId(INT位置){
      返回的位置;
     }     公共查看getView(INT位置,查看convertView,父母的ViewGroup){
      ViewHolder持有人;
      如果(convertView == NULL){
       convertView = mInflater.inflate(R.layout.homelistvwlyout,NULL);
       持有人=新ViewHolder();
       holder.txtName =(TextView中)convertView.findViewById(R.id.textView1);
       holder.iv =(ImageView的)convertView.findViewById(R.id.imageView1);
       holder.txtvwid =(TextView中)convertView.findViewById(R.id.textView2);
       convertView.setTag(保持器);
      }其他{
       支架=(ViewHolder)convertView.getTag();
      }        holder.txtName.setText(searchArrayList.get(位置));
//光标cursorQuote = database.rawQuery(
//SELECT * FROM Qotestable,其中Notification_Status = 1,
// 空值);
        光标cursorQuote = database.query(Qotestable,空,
                Notification_Status+= 1,NULL,NULL,NULL,Quote_ID
                        +DESC);        如果(cursorQuote.moveToFirst()){
            做{                list.add(cursorQuote.getString(3));
                listid.add(cursorQuote.getString(0));
            }而(cursorQuote.moveToNext());
        }
        //Collections.sort(list,Collections.reverseOrder());
        字符串s = list.get(位置);
        如果(s.contentEquals(1)){
            holder.iv.setImageResource(R.drawable.onestaron);        }否则如果(s.contentEquals(2)){
            holder.iv.setImageResource(R.drawable.twostaron);
        }否则如果(s.contentEquals(3)){
            holder.iv.setImageResource(R.drawable.threestaron);
        }
        holder.txtvwid.setText(listid.get(位置));      返回convertView;
     }     静态类ViewHolder {
      TextView的txtName的,txtvwid;
      TextView的txtCityState;
      ImageView的IV;
      TextView的txtPhone;
     }
    }


解决方案

好吧,没有承诺,我没有你的完整源$ C ​​$ C,但这些都是修改我会做你的适配器类:

 公共类MySimpleArrayAdapter延伸BaseAdapter {    //重命名这些以匹配您的数据库列名
    私有静态最终诠释SOME_DATABASE_COLUMN_NAME_ZERO = 0;
    私有静态最终诠释SOME_DATABASE_COLUMN_NAME_THREE = 3;    私人的ArrayList<串GT; mSearchArrayList;
    私人光标mCursorQuote;    公共MySimpleArrayAdapter(上下文的背景下,ArrayList的<串GT;业绩){
        mSearchArrayList =结果;
        SQLiteDatabase mDatabase = context.openOrCreateDatabase(ORCL,context.MODE_PRIVATE,NULL);
        mCursorQuote = mDatabase.query(Qotestable,空,
                Notification_Status+= 1,NULL,NULL,NULL,Quote_ID
                        +DESC);
    }    公众诠释的getCount(){
        返回mSearchArrayList.size();
    }    公共对象的getItem(INT位置){
        返回mSearchArrayList.get(位置);
    }    众长getItemId(INT位置){
        返回的位置;
    }    公共查看getView(INT位置,查看convertView,父母的ViewGroup){
        ArrayList的<串GT;名单=新的ArrayList<串GT;();
        ArrayList的<串GT; listid =新的ArrayList<串GT;();
        ViewHolder支架=无效;        如果(convertView == NULL){
            LayoutInflater李= LayoutInflater.from(parent.getContext());
            convertView = li.inflate(R.layout.homelistvwlyout,NULL);
            持有人=新ViewHolder(convertView);
            convertView.setTag(保持器);
        }其他{
            支架=(ViewHolder)convertView.getTag();
        }        holder.txtName.setText(mSearchArrayList.get(位置));        如果(mCursorQuote.moveToFirst()){
            做{
                list.add(mCursorQuote.getString(SOME_DATABASE_COLUMN_NAME_THREE)); //没有魔法值
                listid.add(mCursorQuote.getString(SOME_DATABASE_COLUMN_NAME_ZERO)); //没有魔法值
            }而(mCursorQuote.moveToNext());
        }
        字符串s = list.get(位置);
        如果(s.contentEquals(1)){
            holder.iv.setImageResource(R.drawable.onestaron);
        }否则如果(s.contentEquals(2)){
            holder.iv.setImageResource(R.drawable.twostaron);
        }否则如果(s.contentEquals(3)){
            holder.iv.setImageResource(R.drawable.threestaron);
        }其他{
            //你需要其他情况下设置您的ImageView - >这可能是你的问题
            holder.iv.setImageResource(R.drawable.YOUNEEDSOMETHINGHERE);
        }
        holder.txtvwid.setText(listid.get(位置));        返回convertView;
    }    静态类ViewHolder {
        TextView的txtName的;
        TextView的txtvwid;
        ImageView的IV;        / **
         *采用一个视图构造函数将鼓励旁边的人做正确的事与昂贵的呼叫
         * findViewById()
         *
         * @参数v
         * /
        ViewHolder(视图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);
        }
    }
}

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 when I scroll down/up the list, images get shuffled and I don't know what to do.

public class MySimpleArrayAdapter extends BaseAdapter {
     private static ArrayList<String> searchArrayList;
     SQLiteDatabase database;


     private LayoutInflater mInflater;
     ArrayList<String> list = new ArrayList<String>();
     ArrayList<String> listid = new ArrayList<String>();

     public MySimpleArrayAdapter(Context context, ArrayList<String> results) {
      searchArrayList = results;
      mInflater = LayoutInflater.from(context);
      database = context.openOrCreateDatabase("ORCL", context.MODE_PRIVATE, null);
     }

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

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

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

     public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder;
      if (convertView == null) {
       convertView = mInflater.inflate(R.layout.homelistvwlyout, null);
       holder = new ViewHolder();
       holder.txtName = (TextView) convertView.findViewById(R.id.textView1);
       holder.iv = (ImageView) convertView.findViewById(R.id.imageView1);
       holder.txtvwid = (TextView) convertView.findViewById(R.id.textView2);
       convertView.setTag(holder);
      } else {
       holder = (ViewHolder) convertView.getTag();
      }

        holder.txtName.setText(searchArrayList.get(position));
//      Cursor cursorQuote = database.rawQuery(
//              "SELECT * FROM  Qotestable where Notification_Status =1",
//              null);
        Cursor cursorQuote = database.query("Qotestable", null,
                "Notification_Status" + "=1", null, null, null, "Quote_ID"
                        + "DESC");



        if (cursorQuote.moveToFirst()) {
            do {

                list.add(cursorQuote.getString(3));
                listid.add(cursorQuote.getString(0));
            } while (cursorQuote.moveToNext());
        }
        //Collections.sort(list, Collections.reverseOrder()); 
        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);
        }
        holder.txtvwid.setText(listid.get(position));

      return convertView;
     }

     static class ViewHolder {
      TextView txtName,txtvwid;
      TextView txtCityState;
      ImageView iv;
      TextView txtPhone;
     }
    }
解决方案

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);
        }
    }
}

这篇关于图像获得洗牌或更改,当我在列表视图滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 10:32