1

我有一个 multicolumn_listview。某些行在列表视图中重复。我查看了有关此问题的所有解决方案。

列表视图项目图像

  1. Listview 高度不是 wrap_content
  2. 我的持有人类静态
  3. if(convertView==null)在 getview 方法中创建了块中的所有视图。

但问题还没有解决..请帮助我..

这是我的适配器类;

public class ListViewAdapterCurrentList extends BaseAdapter
{
    public ArrayList<HashMap<String, String>> list;
    boolean isDetail = false;
    private String currentNo;
    private String currentCode;
    private String currentName;
    private String date;
    private String status;
    private Activity activity;
    private Boolean isPlan = true;

    public ListViewAdapterCurrentList(Activity activity, ArrayList<HashMap<String, String>> list, boolean isPlan) {
        super();
        this.activity = activity;
        this.list = list;
        this.isPlan = isPlan;
    }

    @Override
    public int getCount()
    {
        return list.size();
    }

    @Override
    public Object getItem(int position)
    {
        return list.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        return 0;
    }

    static class ViewHolder
    {
        ImageView currentDetail;
        TextView currentNo;
        TextView currentCode;
        TextView currentName;
        TextView date;
        TextView durum;
        LinearLayout linearLayoutCurrentBase;
        LinearLayout linearLayoutCurrentDetail;
        TextView currentAddress;
        TextView currentPhone;
        TextView currentManager;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        final ViewHolder holder;
        LayoutInflater inflater = activity.getLayoutInflater();
        final HashMap<String, String> map = list.get(position);

        if (convertView==null)
        {
            Log.d("CL:getView()", "Fetching Row: " + position);
            convertView = inflater.inflate(R.layout.currentlistitems, parent, false);
            holder = new ViewHolder();
            holder.currentDetail = (ImageView) convertView.findViewById(R.id.imageViewCurrentListDetail);
            holder.currentNo = (TextView) convertView.findViewById(R.id.textViewCurrentListNo);
            holder.currentCode = (TextView) convertView.findViewById(R.id.textViewCurrentListCode);
            holder.currentName = (TextView) convertView.findViewById(R.id.textViewCurrentListName);
            holder.date = (TextView) convertView.findViewById(R.id.textViewCurrentListDate);
            holder.durum = (TextView) convertView.findViewById(R.id.textViewCurrentListStatus);
            holder.linearLayoutCurrentBase = (LinearLayout) convertView.findViewById(R.id.layoutBaseCurrentList);
            holder.linearLayoutCurrentDetail = (LinearLayout) convertView.findViewById(R.id.layoutDetailCurrentList);
            holder.currentAddress = (TextView) convertView.findViewById(R.id.textViewCurrentAddress);
            holder.currentPhone = (TextView) convertView.findViewById(R.id.textViewCurrentPhone);
            holder.currentManager = (TextView) convertView.findViewById(R.id.textViewCurrentManager);
            convertView.setTag(holder);
        } else
        {
            holder = (ViewHolder) convertView.getTag();
        }
        currentNo = map.get("CariNo");
        currentCode = map.get("CariKod");
        currentName = map.get("CariUnvan");
        date = map.get("Tarih");
        status = map.get("Durum");
        holder.currentDetail.setBackgroundResource(R.drawable.box_plus);
        holder.currentNo.setText(currentNo);
        holder.currentCode.setText(currentCode);
        holder.currentName.setText(currentName);
        holder.date.setText(date);
        holder.durum.setText(status);
        if (!isPlan)
        {
            holder.durum.setVisibility(View.GONE);
            holder.date.setVisibility(View.GONE);
            holder.currentName.setWidth(300);
        }
        initDetailInfo(holder.currentAddress, holder.currentPhone, holder.currentManager, currentNo);

        holder.currentDetail.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                if (!isDetail)
                {
                    holder.linearLayoutCurrentDetail.setVisibility(View.VISIBLE);
                    holder.currentDetail.setBackgroundResource(R.drawable.box_delete_expand);
                    isDetail = true;
                } else
                {
                    holder.linearLayoutCurrentDetail.setVisibility(View.GONE);
                    holder.currentDetail.setBackgroundResource(R.drawable.box_plus);
                    isDetail = false;
                }
            }
        });

        return convertView;
    }
4

1 回答 1

0

编辑,因为它显然不清楚:

if (convertView==null)
{
    Log.d("CL:getView()", "Fetching Row: " + position);
    convertView = inflater.inflate(R.layout.currentlistitems, parent, false);
    holder = new ViewHolder();
    holder.currentDetail = (ImageView) convertView.findViewById(R.id.imageViewCurrentListDetail);
    holder.currentNo = (TextView) convertView.findViewById(R.id.textViewCurrentListNo);
    holder.currentCode = (TextView) convertView.findViewById(R.id.textViewCurrentListCode);
    holder.currentName = (TextView) convertView.findViewById(R.id.textViewCurrentListName);
    holder.date = (TextView) convertView.findViewById(R.id.textViewCurrentListDate);
    holder.durum = (TextView) convertView.findViewById(R.id.textViewCurrentListStatus);
    holder.linearLayoutCurrentBase = (LinearLayout) convertView.findViewById(R.id.layoutBaseCurrentList);
    holder.linearLayoutCurrentDetail = (LinearLayout) convertView.findViewById(R.id.layoutDetailCurrentList);
    holder.currentAddress = (TextView) convertView.findViewById(R.id.textViewCurrentAddress);
    holder.currentPhone = (TextView) convertView.findViewById(R.id.textViewCurrentPhone);
    holder.currentManager = (TextView) convertView.findViewById(R.id.textViewCurrentManager);
    convertView.setTag(holder);
} else
{
    holder = (ViewHolder) convertView.getTag();
}

在对他们进行任何工作之前就在上面,例如将孩子添加到LinearLayouts

holder.linearLayoutCurrentBase.removeAllViews();
holder.linearLayoutCurrentDetail.removeAllViews();

我的猜测是,因为您没有使用 Viewgroups 这样做,所以它永远不会取代孩子。让我知道这是否有帮助。

编辑:

我只是希望最后一次编辑答案。对于使用错误的方法删除 ViewGroups 的子项,我深表歉意。现在它应该是有道理的。查看我的评论以了解为什么它会重复您的视图。

于 2013-08-12T15:40:06.127 回答