不调用Array适配器类的getView()方法

时间:2017-11-27 13:41:30

标签: android

在我的自定义数组适配器类中,getView()回调不会被调用。 我已经检查了太多关于互联网和这个大小的问题,但我还没有找到任何解决方案。 这是我的AdapterClass

class HistoryAdapter extends ArrayAdapter<RefelModal>{

    public HistoryAdapter(List<RefelModal> items) {
        super(getActivity(), R.layout.view_refel_history_row,items);
        System.out.println("Call hits");
        System.out.println("And item list size ======"+items.size());
    }

    class ViewHolder{
        UrduTextView sno,familyPlanning,disease,healthCenter,date,doctor;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        System.out.println("getView callback hit");
        RefelModal item = getItem(position);

        ViewHolder holder;
        if(view == null){
            System.out.println("getView callback hit and view is null");
            view = root.findViewById(R.layout.view_refel_history_row);
            holder = new ViewHolder();
            holder.sno = (UrduTextView) view.findViewById(R.id.sno);
            holder.familyPlanning = (UrduTextView) view.findViewById(R.id.familyPlanning);
            holder.disease = (UrduTextView) view.findViewById(R.id.disease);
            holder.healthCenter = (UrduTextView) view.findViewById(R.id.healthCenter);
            holder.date = (UrduTextView) view.findViewById(R.id.date);
            holder.doctor = (UrduTextView) view.findViewById(R.id.doctor);
            view.setTag(holder);
        }
        else{
            holder = (ViewHolder) view.getTag();
        }

        holder.sno.setText(String.valueOf(position + 1));
        holder.familyPlanning.setText(item.getFamilyPlanning().getName());
        holder.disease.setText(item.getDisease().getName());
        holder.healthCenter.setText(item.getHealthCenter().getName());
        holder.date.setText(Helper.FormatDate(item.getHealthCenterDate()));
        holder.doctor.setText(item.getHealthCenterDoctor().getName());

        return view;
    }

}

并在initControl()中我将适配器设置如下

 ListView selected = (ListView) root.findViewById(R.id.selected);
    selected.setAdapter(selectedAdapter = new SelectedAdapter(Constants.getDatabase(getActivity()).getSelectedReferal(MemberDetailActivity.MEMBER_ID)));

我的问题的任何解决方案

1 个答案:

答案 0 :(得分:0)

您需要返回项目数。

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