java Android Studio无法解析列表适配器中的方法
我创建了一个自定义列表适配器,它从基本适配器扩展而来,因为我需要在列表中输入两个数组。代码如下:
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调用最后两个方法UpdateValue和updateDescriptions。当我试图给他们打电话时,安卓工作室说了
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管理器和列表适配器在onStart中初始化。为什么我会犯这个错误
# 1 楼答案
使用OwellistAdapter代替ListAdapter,就像使用自定义适配器一样
# 2 楼答案
将main活动从
ListAdapter oweAdapter
更改为OweListAdaptor oweAdapter
,它将起作用