0

I put a Console.WriteLine() in GetView() method of a custom adapter, like so: (Please note the code is in c# and I cant use the duplicate answer because I cant inherit from an abstact method in c#)

    public override View GetView(int position, View convertView, ViewGroup parent)
    {
        View row = convertView;

        if (row == null)
        {
            row = LayoutInflater.From(myContext).Inflate(Resource.Layout.ExerciseRowBig, null, false);
        }

        Console.WriteLine("Hello");

        return row;
    }

And the problem is that the debugger shows the message "Hello" twice, even though there is only one item in the ListView. Why? Is it intended?

Miko M
  • 29
  • 7
  • Please print `Environment.StackTrace` to the console too and post the results. – Eugene Komisarenko Jun 19 '17 at 16:56
  • I found out why according to this article. https://stackoverflow.com/questions/5230155/android-getview-called-twice-in-custom-adapter – Miko M Jun 19 '17 at 17:02
  • I just dont know how to implement it in c# becase `base.GetView()` is abstract. – Miko M Jun 19 '17 at 17:02
  • `StackTrace` doesnt exist in Environment for me – Miko M Jun 19 '17 at 17:06
  • Please help me migrating the code to c# – Miko M Jun 19 '17 at 17:19
  • "I just dont know how to implement it in c#" - Implement what, exactly? That's just how `Adapter`s work. There is no guarantee as to how many times or in which order `GetView()` will be called. You shouldn't have any logic there that relies on those things. – Mike M. Jun 19 '17 at 18:27

0 Answers0