我创建了一个扩展 BaseAdapter 的类。我没有任何 custom.xml 来膨胀它。很简单,我写了这段代码
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();//Getting Error here to create a method getLayoutInflater
View row;
row = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
TextView title;
title = (TextView) row.findViewById(android.R.id.text1);
title.setText(Title[position]);
return (row);
}
在 getLayoutInflater() 上,它向我显示创建方法的错误。如果我在主要活动中创建此类,那么它可以正常工作。所以我必须做些什么来消除这个错误
为了创建ListView,我将适配器称为
myAdapter = new dataListAdapter(this,passengerList);
listView.setAdapter(myAdapter);
对于ListView项目的更新,我将适配器称为
update.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(isSuccess){
dialog.cancel();
passengerList[position] = newString;
listView.setAdapter(new dataListAdapter(this,passengerList));
}
}
});
我的 BaseAdapter 类
class PassengerListView extends BaseAdapter {
String[] Title;
Activity activity;
public dataListAdapter(MainActivity mainActivity, String[] text) {
Title = text;
activity = mainActivity;
}
public String[] getAllValues() {
return Title;
}
public int getCount() {
// TODO Auto-generated method stub
return Title.length;
}
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = activity.getLayoutInflater();//Getting Error here to create a method getLayoutInflater
View row = null;
if(convertView == null) {
row = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
}
TextView title;
title = (TextView) row.findViewById(android.R.id.text1);
title.setText(Title[position]);
return (row);
}
所以在更新代码上它向我显示了这个错误:
构造函数 PassengerListView(new View.OnClickListener(){}, String[]) 未定义