您好我正在测试以下代码,它假设列出安装在Android机器上的所有应用程序。 要编辑编译,我使用AIDE 一个android java编辑器问题是AIDE总是给我一个错误:“未知方法'getTitle'”。 有人可以帮我吗?
public class AppListAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private List<App> mApps;
public AppListAdapter(Context context) {
// cache the LayoutInflater to avoid asking for a new one each time
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return mApps.size();
}
@Override
public Object getItem(int position) {
return mApps.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int pos, View convertView, ViewGroup parent) {
AppViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.row, null);
// creates a ViewHolder and stores a reference to the child view
holder = new AppViewHolder();
holder.mTitle = (TextView) convertView.findViewById(R.id.apptitle);
convertView.setTag(holder);
} else {
// reuse/overwrite the view passed assuming(!) that it is castable!
holder = (AppViewHolder) convertView.getTag();
}
holder.setTitle(mApps.get(pos).getTitle());
return convertView;
}
public void setListItems(List<App> list) {
mApps = list;
}
/**
* A view holder which is used to reuse views inside a list.
*/
public class AppViewHolder {
private TextView mTitle;
/**
* Sets the text to be shown as the app's title
*
* @param title the text to be shown inside the list row
*/
public void setTitle(String title) {
mTitle.setText(title);
}
}
}
答案 0 :(得分:0)
mApps.get(pos)
返回类型为App
您必须在getTitle
类中创建App
方法。
答案 1 :(得分:0)
您的应用类
中可能没有 getTitle()方法