Click here to Skip to main content
14,693,774 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, seriennummerList)
                {
                    @NonNull
                    @Override
                    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent)
                    {
                        View view = super.getView(position, convertView, parent);
                        boolean treffer = false;
                        if(seriennummerList.size() != 0)
                        {
                            if(serverresponseList.size() != 0)
                            {
                                view.setBackgroundColor(Color.GREEN);

                                for(String serie : serverresponseList)
                                {
                                    for (String server : seriennummerList)
                                    {
                                        if(serie.equals(server))
                                        {
                                            view.setBackgroundColor(Color.RED);
                                            treffer = true;
                                            break;
                                        }
                                    }
                                    if(!treffer)
                                    {
                                        view.setBackgroundColor(Color.GREEN);
                                    }
                                    treffer = false;

                                }
                            }
                            else
                            {
                                view.setBackgroundColor(Color.GREEN);
                            }
                        }
                        return  view;
                    }
                };
                adapter.notifyDataSetChanged();
                listView.setAdapter(adapter);


What I have tried:

adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, seriennummerList)
                {
                    @NonNull
                    @Override
                    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent)
                    {
                        View view = super.getView(position, convertView, parent);
                        boolean treffer = false;
                        if(seriennummerList.size() != 0)
                        {
                            if(serverresponseList.size() != 0)
                            {
                                view.setBackgroundColor(Color.GREEN);

                                for(String serie : serverresponseList)
                                {
                                    for (String server : seriennummerList)
                                    {
                                        if(serie.equals(server))
                                        {
                                            view.setBackgroundColor(Color.RED);
                                            treffer = true;
                                            break;
                                        }
                                    }
                                    if(!treffer)
                                    {
                                        view.setBackgroundColor(Color.GREEN);
                                    }
                                    treffer = false;

                                }
                            }
                            else
                            {
                                view.setBackgroundColor(Color.GREEN);
                            }
                        }
                        return  view;
                    }
                };
                adapter.notifyDataSetChanged();
                listView.setAdapter(adapter);
Posted
Comments
David Crow 14-Jul-20 14:23pm
   
Why did you post code twice? If there's no difference between the two, remove one. Otherwise, folks reading this are going to be toggling back and forth between the two trying to figure out what you did differently.
David Crow 14-Jul-20 14:35pm
   
So what's (not) happening?

I would recommend something like:
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent)
{
    if (convertView == null)
    {
        LayoutInflater vi = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = vi.inflate(resource_id_of_row, parent, false);
    }

    int nColor = Color.Green;

    // conditions that could change color go here

    convertView.setBackgroundColor(nColor);

    return convertView;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900