Android Studio 无法解析列表适配器中的方法

Android Studio Cannot Resolve Method in List Adapter

我创建了一个从基本适配器扩展的自定义列表适配器,因为我需要将两个数组输入到列表中。代码如下:

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();
}

不能从 MainActivity 调用最后两个方法 updateValues 和 updateDescriptions。当我尝试给他们打电话时,Android Studio 说

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

要调用它,我只是在 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);
}

DB Manager 和List Adapter 在onStart 中初始化。为什么会出现此错误?

将您的 MainActivity 从 ListAdapter oweAdapter 更改为 OweListAdaptor oweAdapter,它将起作用。

使用 OweListAdapter 代替 ListAdapter,因为您使用的是自定义适配器。