ListView项目中Viewgroup中的随机项

时间:2012-04-26 09:59:45

标签: java android listview viewgroup

我有一个列表视图和内部列表视图,每个项目都是一个线性布局,其中包含textview和一个由Java代码添加的textviews视图组。但是列表显示正确的列表项文本视图,但在视图组内显示随机文本视图。有意见或建议的人吗?


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

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;


我使用了this site

中给出的FlowLayout

0 个答案:

没有答案