Android Studio无法解析列表适配器

时间:2016-06-23 12:30:28

标签: java android listview baseadapter

我创建了一个从Base Adapter扩展的自定义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会说它

  

无法解析方法'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);
}

数据库管理器和列表适配器在onStart中初始化。为什么我会收到此错误?

2 个答案:

答案 0 :(得分:0)

将您的MainActivity从ListAdapter oweAdapter更改为OweListAdaptor oweAdapter,这样就可以了。

答案 1 :(得分:0)

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