1

I am fairly new to android development and when I try to work with adapters in fragments I get an error, I tried to write this line under the onCreateView

valueAdapterEn = new ValueAdapterEn(English_list, this);

this error is in this section (English_list, this)

ValueAdapterEn

public class ValueAdapterEn extends BaseAdapter implements Filterable {

private ArrayList<String> English_List;
private ArrayList<String> Filterd_EngList;
private LayoutInflater mInflater;
private ValueFilter valueFilter;

public ValueAdapterEn(ArrayList<String> English_List, Context context){
    this.English_List = English_List;
    this.Filterd_EngList = English_List;
    mInflater = LayoutInflater.from(context);
    getFilter();
}

@Override
public int getCount() {
    return 0;
}

@Override
public Object getItem(int position) {
    return null;
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    return null;
}

@Override
public Filter getFilter() {
    return null;
 }
}

LogCat

Error:(84, 30) error: constructor ValueAdapterEn in class ValueAdapterEn cannot be applied to given types;
required: no arguments
found: ArrayList<String>,TwoFragment
reason: actual and formal argument lists differ in length

the problem may be with 'this'

Thorvald
  • 3,424
  • 6
  • 40
  • 66

4 Answers4

2

You have create this ValueAdapterEn class with no arguments in the constuctor as the log message shows there I guess.How can you pass arguments in the class.Please also post your relevant code for more help and also learn core-java first before deep digging into some android code.You can lean about constructor from this and this.

Soham
  • 4,397
  • 11
  • 43
  • 71
1

your ValueAdapterEn Constructor is not taking the Context:

You have to instantiate your context like below ;

  public class ValueAdapterEn extends BaseAdapter implements Filterable {
  private Context context;
     public ValueAdapterEn(ArrayList<String> English_List, Context context){
             this.context = context ;
   }
   ......

  }
Ahlem Jarrar
  • 1,129
  • 1
  • 12
  • 33
0

instead of this you have to pass context Or getActivity()

Deepak Kumar
  • 1,035
  • 10
  • 18
0

I'm not allowed to comment yet, but I guess the adapter there requires a context, which you're trying to pass in the second argument. A fragment is not a valid context. Use getActivity() instead of this.

meedz
  • 132
  • 13
  • I added the LogCat, please take time to review it, and I tried getActivity() but it didn't work – Thorvald Aug 18 '16 at 11:20
  • I looked at it. Looks like your instantiation has too many or too few arguments. Can I see you constructor? – meedz Aug 18 '16 at 11:26
  • 1
    Please don't post guesses as answers. – Iulian Popescu Aug 18 '16 at 11:27
  • as I said I am not familiar with such words, excuse my ignorance but what is exactly a constructor ?? – Thorvald Aug 18 '16 at 11:31
  • @IulianPopescu I'm trying to help them and I can't comment. – meedz Aug 18 '16 at 11:33
  • @SígvardrÓlavrsson the beginning of the class. The part that says Public class ValueAdapterEn extends ...... – meedz Aug 18 '16 at 11:35
  • 1
    You don't help if you post random thoughts (excepting the fact that the same answer was already posted). To give a proper answer wait until you can be sure that what you say will fix the problem – Iulian Popescu Aug 18 '16 at 11:36
  • I added the constructor – Thorvald Aug 18 '16 at 11:39
  • @IulianPopescu The same answer was posted literally as mine was going through. Call it a race condition. As to whether or not I'm helping, I'm sure that's OP's call. – meedz Aug 18 '16 at 11:49
  • @SígvardrÓlavrsson That's the class definition. Inside it, you will find Public ValueAdapteEn( and then a bunch of stuff. Can you post that? – meedz Aug 18 '16 at 11:53