Blanc行listview

时间:2016-10-18 10:19:41

标签: android listview

我不知道为什么,但ListView的行是空白的。当我点击某个项目时,新的Activity将以对象的信息开头。但行是空白的。

getView()的方法Adapter

@Override
public View getView(int position, View convertView, ViewGroup parent) {

   MyViewHolder myViewHolder = null;
   if(convertView==null){
       LayoutInflater mInflater=(LayoutInflater) c.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
       convertView=mInflater.inflate(layout, parent, false);

       myViewHolder=new MyViewHolder();
       if(layout==R.layout.medoc_item_for_list){
           myViewHolder.nom=(TextView) convertView.findViewById(R.id.textView_medocName_itemForList);
           myViewHolder.image=(ImageView) convertView.findViewById(R.id.imageView_itemForList);
           myViewHolder.date=(TextView)convertView.findViewById(R.id.textView_peremptionDate_itemForList);
           myViewHolder.nbrPillule=(TextView)convertView.findViewById(R.id.textView_nbrPillule_itemForList);
       }
       else if(layout==R.layout.medoc_item_for_grid){
           //TODO
       }

       convertView.setTag(myViewHolder);
   }else{
       myViewHolder = (MyViewHolder) convertView.getTag();
   }
   Medicament medoc=(Medicament) getItem(position);
   myViewHolder.nom.setText(medoc.getName());
   if(layout==R.layout.medoc_item_for_list){
       Calendar peremption=medoc.getDate();
       if(peremption==null){
           myViewHolder.date.setText("-");
       }
       else{
           myViewHolder.date.setText(formatter(peremption.get(Calendar.DAY_OF_MONTH))+"/"+formatter(peremption.get(Calendar.MONTH))+"/"+peremption.get(Calendar.YEAR));
       }
       myViewHolder.nbrPillule.setText(String.valueOf(medoc.getNbrPillule()));//String.valueOf car setText peut aussi prendre un id qui est un entier
       if(medoc.getImage() !=null){
           myViewHolder.image.setImageResource(medoc.getImage());
       }
   }
   return convertView;
}

1 个答案:

答案 0 :(得分:0)

布局由此方法给出:

public void invertAffichage(){
if(layoutForAdaptater==R.layout.medoc_item_for_list){
    //remplace par grid
    listeView.setVisibility(View.GONE);
    gridView.setVisibility(View.VISIBLE);
    layoutForAdaptater=R.layout.medoc_item_for_grid;
    adaptater=new CustoAdaptater(getApplicationContext(), data, layoutForAdaptater);
    gridView.setAdapter(adaptater);
    gridView.setOnItemClickListener(adaptater);
}else if(layoutForAdaptater==R.layout.medoc_item_for_grid){
    //remplace par list
    listeView.setVisibility(View.VISIBLE);
    gridView.setVisibility(View.GONE);
    layoutForAdaptater=R.layout.medoc_item_for_list;
    adaptater=new CustoAdaptater(getApplicationContext(), data, layoutForAdaptater);
    listeView.setAdapter(adaptater);
    listeView.setOnItemClickListener(adaptater);
}else{
    //TODO error
}

} 我尝试添加在listView和gridView之间切换的可能性。