0

您好,我正在测试以下代码,它假设列出了安装在 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);
     }
  }
}
4

2 回答 2

0
 mApps.get(pos)

返回一个类型的对象App

您必须getTitle在类中创建一个方法App

于 2012-06-24T22:26:06.353 回答
0

您的App类中可能没有getTitle()方法

于 2012-06-24T22:26:40.487 回答