List item repeating in android customized listview

前端 未结 4 1578
不知归路
不知归路 2020-12-03 12:38

In my customized list view items are repeating.position of item is same for all item. code is below

ListAdapter.java-

    public class ListAdapter ex         


        
4条回答
  •  失恋的感觉
    2020-12-03 13:07

    Make sure the convertView is not null. Hence place all code after the if(convertView == null){ } which ensures you have a convertView whose value is not null, by inflating from context if so.

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
    
      if (convertView == null) {
        LayoutInflater inflater = LayoutInflater.from(context);
        convertView = inflater.inflate(R.layout.list_menu, parent, false);
      } 
    
      TextView mText=(TextView) convertView.findViewById(R.id.appName);
      ImageView mImage=(ImageView) convertView.findViewById(R.id.appIcon);
      CheckBox mCheckBox=(CheckBox) convertView.findViewById(R.id.mCheckbox);
    
      mText.setText(mName.get(position));
      mImage.setImageDrawable(mIcon.get(position));
    
      return convertView;
    }
    

提交回复
热议问题