在使用GridView、ListView的过程中遇到内容错乱的问题,费了较长时间才找到问题的根源,特地总结一下。
1、在自定义adapter中没有给每一项都设置内容导致内容错乱:
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if( null == convertView ){
mGridHolder = new GridHolder( );
convertView = mLayoutInflater.inflate( R.layout.view_log_word_item_layout, null );
mGridHolder.mBackTopLayout = (LinearLayout)convertView.findViewById( R.id.logItemTopLayoutId);
mGridHolder.mBackBottomLayout = ( RelativeLayout )convertView.findViewById( R.id.logItemBottomLayoutId );
mGridHolder.mRightWordTxt = ( TextView )convertView.findViewById( R.id.rightWordTxtId );
mGridHolder.mUserWriteImg = ( ImageView )convertView.findViewById( R.id.userWordImgId );
mGridHolder.mWriteResultImg = ( ImageView )convertView.findViewById( R.id.writeResultImgId );
mGridHolder.mReasonTxt = ( TextView )convertView.findViewById( R.id.reasonTxtId );
mGridHolder.mRightWordTxt.setTypeface( mTypeface );
convertView.setTag( mGridHolder );
}else{
mGridHolder = ( GridHolder )convertView.getTag( );
}
showContent( mDictationInfoList.get( position ) );
return convertView;
}
@SuppressWarnings("deprecation")
private void showContent( DictationInfo dictationInfo ){
mGridHolder.mRightWordTxt.setText( dictationInfo.getmWord( ) );