当我在列表视图中滚动时,我的图像被洗牌或更改.......当我向下滚动并继续改变自己时,图像得到洗牌我有一个自定义列表视图适配器,当我向下/向上滚动时列表,图像被洗牌,我不知道该怎么做。
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;
}
}
答案 0 :(得分:0)
您忘记在"Quote_ID"
和"DESC"
之间留出空格,以便您的收藏无序。将"Quote_ID" + "DESC"
更改为"Quote_ID DESC"
。
每次调用getView()时都会查询数据库。除了浪费性能之外,list
和listid
会变得无限大。至少你应该清除它们。如果您不想动态更新内容,则应将此代码移出getView()
。
<强>更新强>
对于给定的cursorQuote.getString(3)
,position
是否不等于“1”,“2”或“3”?在这种情况下,您根本不会分配图像,它仍然保留在convertView中。
答案 1 :(得分:0)
只是一个猜测! ...尝试使用...如果listview
尺寸不大......要保留insertion
和order
中的activity
adapter
Activity/fragment
和adapter
而不是 ::
ArrayList<String> list = new ArrayList<String>();
使用 ::
LinkedList<String> list = new LinkedList<String>();
答案 2 :(得分:0)
请检查你的listview高度.....它不应该是wrap_content .....它应该是match_parent。 如下,
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent" /> ///////HEIGHT SHOULD BE MATCH_PARENT////