我有一个 listView 正在工作/显示一些数据作为 Title 和 subtitle ,一切正常,但是每当我向上滚动列表或 convertView 回收时,最后一个元素的副标题会重复,而 Title 不是,这是什么问题..
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
final ViewHolder viewHolder;
m_oActivatedProfilePreferences =m_oContext.getSharedPreferences(m_kSHARED_PREF_PROFILE_KEY, Context.MODE_PRIVATE);
final CProfileDataSource profileDataSource = new CProfileDataSource(m_oContext);
final List<CUserProfile> profileName = profileDataSource.getAllProfiles();
if(convertView==null)
{
viewHolder=new ViewHolder();
convertView=layoutInflater.inflate(R.layout.profile_description,parent,false);
viewHolder.m_profileName=(TextView) convertView.findViewById(R.id.profilename);
viewHolder.m_radioButton=(RadioButton)convertView.findViewById(R.id.radioButton);
viewHolder.m_profileDetails=(TextView)convertView.findViewById(R.id.pro_details);
viewHolder.m_profileLyt=(LinearLayout)convertView.findViewById(R.id.profile);
if(position==0)
{
viewHolder.m_profileDetails.setText(R.string.general_profile_description);
}else if(position==1)
{
viewHolder.m_profileDetails.setText(R.string.sleep_profile_description);
}else if(position==2)
{
viewHolder.m_profileDetails.setText(R.string.ssaver_profile_description);
}else
{
//here for the 8th position of list it displays the text as position 0
viewHolder.m_profileDetails.setText(R.string.profile_desc);
}
convertView.setTag(viewHolder);
viewHolder.m_radioButton.setChecked(false);
}
else
{
viewHolder = (ViewHolder) convertView.getTag();
viewHolder.m_radioButton.setChecked(false);
}
return convertView;
}
在“else”部分下,“viewHolder.m_profileDetails”将它们的文本设置为位置编号 0,而它在列表中的位置是 8 或 9。
private static class ViewHolder{
RadioButton m_radioButton;
TextView m_profileName;
TextView m_profileDetails;
LinearLayout m_profileLyt;
}