Note that there are some explanatory texts on larger screens.

plurals
  1. POWrong when scroll listview with adapter
    text
    copied!<p>(Sorry I'm not good at English) I haved created a custom BaseAdapter to show my data from sqlite to a ListView. Now I can see list but when i scroll listview quickly, rows are view oddly. I can't understand this. And one more strange point is that, if i have 5 data row, getView run 5 time but only first 4 row can be show. I use log and i see 5 time "return view;" clearly.</p> <p>Here are my adapter code:</p> <pre><code>public class LocalRankAdapter extends BaseAdapter { private static final String FIELD1 = "time"; private static final String FIELD2 = "name"; private static final String TABLE_NAME = "rank"; private static final String FIELD_ORDER = "time"; private DataBaseHelper dbHelper; private Cursor mCursor; private Context mContext; private int timeColIndex; private int nameColIndex; private int index; private int length; public static float recent_time=0; public static String recent_playerName=""; public LocalRankAdapter(Context context, DataBaseHelper mdbHelper) { mContext=context; dbHelper=mdbHelper; // get data from database mCursor = dbHelper.getData(TABLE_NAME, new String[] { FIELD1, FIELD2 }, FIELD1 + " !=0 ", FIELD_ORDER + " ASC"); mCursor.moveToFirst(); length=mCursor.getCount(); timeColIndex=mCursor.getColumnIndex(FIELD1); nameColIndex=mCursor.getColumnIndex(FIELD2); index=1; } public static void insertData(DataBaseHelper dbHelper, float currentTime, String name) { ContentValues cv=new ContentValues(); cv.put(FIELD1, currentTime); cv.put(FIELD2, name); dbHelper.insertData(TABLE_NAME, new String[] {FIELD1, FIELD2}, cv); } @Override public int getCount() { return length-1; } @Override public View getView(int id, View convertView, ViewGroup parent) { View v=convertView; if (convertView == null) { v=convertView; LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = inflater.inflate(R.layout.list_item, parent, false); TextView rankNumber=(TextView) v.findViewById(R.id.txtRank); TextView time=(TextView) v.findViewById(R.id.txtTime); TextView playerName=(TextView) v.findViewById(R.id.txtPlayerName); String timeStr=mCursor.getString(timeColIndex); String playerNameStr=mCursor.getString(nameColIndex); if(Float.parseFloat(timeStr)==(recent_time/1000f) &amp;&amp; playerNameStr.equals(recent_playerName)) { v.setBackgroundColor(mContext.getResources().getColor(R.color.item_bg_recent)); rankNumber.setText(String.valueOf(index++)+" (Your)"); } else rankNumber.setText(String.valueOf(index++)); time.setText(timeStr); playerName.setText(playerNameStr); mCursor.moveToNext(); return v; } return v; } @Override public Object getItem(int id) { return id; } @Override public long getItemId(int arg0) { return 0; } public static void setModeView(int mtime, String mplayerName) { recent_time=mtime; recent_playerName=mplayerName; } </code></pre> <p>}</p>
 

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