我有一个multicolumn_listview。列表视图中的某些行重复。我查看了有关此问题的所有解决方案。
if(convertView==null)
块中创建了所有视图。但问题还没有解决..请帮帮我..
这是我的适配器类;
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;
}
答案 0 :(得分: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的子项而道歉。现在它应该有意义。查看我的评论,了解它为什么会重复你的观点。