出現該問題緣由爲在設置每一個條目的值的時候,將設定值的代碼放在了判斷語句裏面,致使有些條目會重複。java
對list不清楚致使的錯誤,特標記之。app
錯誤代碼以下,設置應用名稱下面的幾行值,實踐證實,他們的賦值須要在判斷條件之外:ide
public View getView(int position, View convertView, ViewGroup parent) {// TODO Auto-generated method stubLog.i(TAG, "getView position = " + position); ViewHolder viewHolder = new ViewHolder();if (convertView == null) { convertView = mInflater.inflate(R.layout.apps_list_item, null); viewHolder.cb_installed = (CheckBox) convertView .findViewById(R.id.cb_checkedApp); viewHolder.iv_appIcon = (ImageView) convertView .findViewById(R.id.iv_app_icon); viewHolder.tv_appName = (TextView) convertView .findViewById(R.id.tv_app_name); // 設置應用名稱 String mAppName = mData.get(position); Log.i("new", "position " + position + " mAppName = " + mAppName); viewHolder.iv_appIcon.setImageResource(R.drawable.ic_launcher); viewHolder.tv_appName.setText(mAppName); viewHolder.cb_installed.setChecked(isSelected.get(position)); convertView.setTag(viewHolder); }else{ viewHolder = (ViewHolder)convertView.getTag(); }return convertView; }
將這些賦值放在外面,修改後以下,正常了。get
public View getView(int position, View convertView, ViewGroup parent) {// TODO Auto-generated method stubLog.i(TAG, "getView position = " + position); ViewHolder viewHolder = new ViewHolder();if (convertView == null) { convertView = mInflater.inflate(R.layout.apps_list_item, null); viewHolder.cb_installed = (CheckBox) convertView .findViewById(R.id.cb_checkedApp); viewHolder.iv_appIcon = (ImageView) convertView .findViewById(R.id.iv_app_icon); viewHolder.tv_appName = (TextView) convertView .findViewById(R.id.tv_app_name); convertView.setTag(viewHolder); }else{ viewHolder = (ViewHolder)convertView.getTag(); } // 設置應用名稱 String mAppName = mData.get(position); Log.i("new", "position " + position + " mAppName = " + mAppName); viewHolder.iv_appIcon.setImageResource(R.drawable.ic_launcher); viewHolder.tv_appName.setText(mAppName); viewHolder.cb_installed.setChecked(isSelected.get(position)); return convertView; }