1

我有一个列表视图,在列表视图中,每个项目都是一个线性布局,带有 textview 和一个由 Java 代码添加的 textview 的视图组。但是该列表显示了正确的列表项文本视图,但视图组内的随机文本视图。有人有建议或想法吗?


抱歉上次我没有添加代码。现在在这里:

View view = null;
        Business b = filteredBusinessList.get(position);
        String ba = "";
        if(b.getAddress().length() > 0 && b.getAddress() != null) {
            ba += b.getAddress()+", ";
        }
        if(b.getDistrict().length() > 0 && b.getDistrict() != null) {
            ba += b.getDistrict();
        }
        if(b.getZoneName().length() > 0 && b.getZoneName() != null) {
            ba += ", " + b.getZoneName();
        }
        if(convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.business_list_item_nolocation, null);
            final NoLocationViewHolder viewHolder = new NoLocationViewHolder();
            viewHolder.tvBusinessName = (TextView) view.findViewById(R.id.tvBusinessName);
            viewHolder.tvBusinessAddress = (TextView) view.findViewById(R.id.tvBusinessAddress);
            viewHolder.flowLayout = (FlowLayout) view.findViewById(R.id.flow_layout);

            if(b.getContactNumber() != null && !b.getContactNumber().equals("")) {
                String[] contactNumbers = b.getContactNumber().split(",");
                int count = contactNumbers.length;
                for(final String numbers : contactNumbers) {
                    Log.d("NUMBER",b.getName() +">>> "+  numbers);
                    final FlowViewHolder fvh = new FlowViewHolder();
                    fvh.tvCon = new TextView(context);
                    fvh.tvCon.setId(11+count++);
                    fvh.tvCon.setText(numbers.trim());
                    fvh.tvCon.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
                    fvh.tvCon.setTextSize(14);
                    fvh.tvCon.setTextColor(Color.WHITE);
                    fvh.tvCon.setTypeface(null, Typeface.BOLD);
                    fvh.tvCon.setPadding(7, 4, 7, 4);
                    fvh.tvCon.setShadowLayer(1, 1, 1, Color.BLACK);
                    fvh.tvCon.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.business_nolocation_call_bg));
                    fvh.tvCon.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            showAlert("contact", numbers);                  
                        }
                    });
                    fvh.tvCon.setOnTouchListener(new OnTouchListener() {

                        @Override
                        public boolean onTouch(View v, MotionEvent event) {
                            switch (event.getAction()) {
                                case MotionEvent.ACTION_DOWN:   ((TextView)v).setBackgroundDrawable(context.getResources().getDrawable(R.drawable.business_nolocation_call_bg_pressed));
                                                                                                ((TextView)v).setTypeface(null, Typeface.BOLD);
                                                                                                break;
                                case MotionEvent.ACTION_CANCEL:
                                case MotionEvent.ACTION_UP: ((TextView)v).setBackgroundDrawable(context.getResources().getDrawable(R.drawable.business_nolocation_call_bg));
                                                                                    break;
                            }
                            return false;
                        }
                    });
                    FlowViewHolder fv = (FlowViewHolder) viewHolder.flowLayout.getTag();
                    viewHolder.flowLayout.addView(fvh.tvCon,new FlowLayout.LayoutParams(3, 3));
                    viewHolder.flowLayout.setTag(fvh);
                }
            }
            view.setTag(viewHolder);
        } else {
            view = convertView;
        }
        NoLocationViewHolder holder = (NoLocationViewHolder) view.getTag();
        holder.tvBusinessName.setText(b.getName());
        holder.tvBusinessAddress.setText(ba);
        return view;


我已经使用了本网站中给出的 FlowLayout

4

0 回答 0