简体   繁体   English

在自定义ListView中动态创建的TextView中重复的项目

[英]Items repeating in dynamically created TextView in custom ListView

I have created the custom ListView and items being repeated in the dynamically created textview inside getView() . 我已经创建了自定义ListView,并且在getView()动态创建的textview中重复了项目。 There is a LinearLayout ll inside the xml file, to where I'm adding the dynamically created TextView. xml文件中有一个LinearLayout ll ,向其中添加动态创建的TextView。 Please check the images for clear idea. 请检查图像以了解清楚的主意。 I think the problem is with List<ModelClinicList> opList = list.get(position).operatingHoursList; 我认为问题出在List<ModelClinicList> opList = list.get(position).operatingHoursList; and for loop inside the getView() 并在getView() for loop

public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        ViewHolder holder = null;

        if (convertView == null)
        {
            LayoutInflater inflater = context.getLayoutInflater();
            convertView = inflater.inflate(R.layout.new_list_clinics, null);
            holder = new ViewHolder(convertView);

            convertView.setTag(holder);


        }
        else
        {
            holder = (ViewHolder)convertView.getTag();
        }

        final String telePhoneNumber = "tel:"+list.get(position).getTelephoneNumber();
        final String latitude = list.get(position).getLatitude();
        final String longitude = list.get(position).getLongitude();
        final String clinicName = list.get(position).getClinicName();
        holder.tvAddress.setText(list.get(position).getAddress());
        holder.tvClinicName.setText(clinicName);

        List<ModelClinicList> opList = list.get(position).operatingHoursList;

        for (int i = 0; i < opList.size(); i++){
            TableRow tableRows = new TableRow(context);
            tableRows.setLayoutParams(params);
            TextView tvLabel = new TextView(context);

            tvLabel.setLayoutParams(tvParams);

            tvLabel.setText(opList.get(i).dayName);

            holder.ll.addView(tvLabel);
        }

        return convertView;
    }

滚动之前

滚动后

You can create one dynamic or static ListView and then write one CustomAdapter. 您可以创建一个动态或静态ListView,然后编写一个CustomAdapter。

Inside the adapter write one TextView and pass the list to the adapter. 在适配器内部编写一个TextView并将列表传递给适配器。 ( I don't know the size of list) (我不知道列表的大小)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM