Two arraylists of different sizes

问题内容:

I have 2 arraylists of different objects. The objects are children and subjects.

Whenever a child id matches with subject id, it means the child has passed and the subject id is deleted in the server. This means I get a list of subjects with that child id deleted. Then both the lists are of different sizes. Subject list size lesser than children list size.

This is my code in fragment –

ArrayList<Children> children = getChildren(getActivity());
 ArrayList<Subjects> subjects = getSubjects(getActivity());

if (children != null && !children.isEmpty()) {

    for (Children child : children) {

        for (Subjects subject : subjects) {

            try {
                int pos = adapter.contains(child.getId());
                if (pos == -1) {
                    data = new ChildListAdapter.childData();
                    data.setChild(child);
                    adapter.addItem(data);

                } else {
                    data = adapter.getItem(pos);
                    data.setChild(child);
                }

                if (subject.getChildId().equalsIgnoreCase(child.getId())) {
                    data.setSubject(subject);
                }


                adapter.notifyDataSetChanged();


            } catch (Exception e) {
                e.getMessage();
            }
        }
    }
}

This is my code in adapter in getView()

if (childData().getChild().getId().equals(childData().getSubject().getChildId())) {

              holder.status.setText("Passed");
            } else {
            //I dont enter here :(
            holder.status.setText("Failed");
            }

The problem is –
a) Whenever the subject list size gets reduced, I need to show the status as “Failed” but currently
i dont enter the else statement. Why is it so?

问题评论:

    
Where do you call getView?
    
Its in the adapter… I extend a BaseAdapter
– Monique890
2 mins ago
    
Move adapter.notifyDataSetChanged() outside the if statement.

原文地址:

https://stackoverflow.com/questions/47756490/two-arraylists-of-different-sizes

添加评论