Search code examples
javaandroidlistviewbaseadapter

Android Studio Cannot Resolve Method in List Adapter


I created a custom List Adapter which extends from Base Adapter because I need to input two arrays into the list. The code is as follows:

public class OweListAdaptor extends BaseAdapter {
String[] descriptionArray, valueArray;
Context context;

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = LayoutInflater.from(context);
    View oweRow = inflater.inflate(R.layout.oweitem, parent, false);

    TextView description = (TextView) oweRow.findViewById(R.id.descText);
    TextView value = (TextView) oweRow.findViewById(R.id.valText);
    description.setText(descriptionArray[position]);
    value.setText(valueArray[position]);

    return oweRow;
}

public OweListAdaptor(String[] description, String[] value) {
    this.descriptionArray = description;
    this.valueArray = value;
}

public void updateValues(String[] newList){
    for (int i=0; i< newList.length; i++){
        valueArray[i] = newList[i];
    }
    this.notifyDataSetChanged();
}

public void updateDescriptions(String[] newList){
    for (int i=0; i< newList.length; i++){
        descriptionArray[i] = newList[i];
    }
    this.notifyDataSetChanged();
}

The last two methods, updateValues and updateDescriptions, cannot be called from MainActivity. When I attempt to call them, Android Studio says it

cannot resolve method 'updateValues(java.lang.String[])'

To call it, I am simply using the following in MainActivity.

public class MainActivity extends AppCompatActivity {
String[] descriptionList, valueList;
OweDBManager DB;
ListAdapter oweAdapter;

public void updateLists(){
    descriptionList = DB.DBtoArray("desc");
    valueList = DB.DBtoArray("value");
    oweAdapter.updateValues(valueList);
}

The DB Manager and List Adapter are initialized in onStart. Why am I getting this error?


Solution

  • change in your MainActivity from ListAdapter oweAdapter to OweListAdaptor oweAdapter and it will work.