Cannot infer type arguments for ArrayAdapter<>

后端 未结 4 1357
感情败类
感情败类 2021-02-20 08:06

I am still playing around with my calendar, I already nearly managed to integrate the https://github.com/SundeepK/CompactCalendarView into one of my fragments. There is just one

相关标签:
4条回答
  • 2021-02-20 08:39

    You need to pass a Context to the Constructor of ArrayAdapter. You're actually in initializing it in a Fragment class, so this is not valid as a Context. Try calling

    final ArrayAdapter adapter = new ArrayAdapter<String>(getActivity(), 
                                    android.R.layout.simple_list_item_1,
                                    mutableBookings);
    
    0 讨论(0)
  • 2021-02-20 08:43

    Try using type in your Adapter declaring. You are missing the type of your mutableBookings:

    final ArrayAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mutableBookings);
    
    0 讨论(0)
  • 2021-02-20 08:48

    If you are in a Fragment so you should use

    ArrayAdapter<String> adapter = new ArrayAdapter<>(**getContext()**,android.R.layout.simple_list_item_1,items);
    
    0 讨论(0)
  • 2021-02-20 08:50

    Sometimes the methods do not run directly in the activity and do not have access to it, not because of this, but because of the getApplicationContext ()

        ArrayAdapter adapter = new ArrayAdapter<>(getApplicationContext(), android.R.layout.simple_list_item_1, mutableBookings);
    
    0 讨论(0)
提交回复
热议问题