没有为Activity类型定义getItemView

时间:2013-10-24 09:58:43

标签: android parse-platform custom-adapter

我正在使用Parse作为我的后端,并使用ParseQueryAdapter来填充listview。根据他们的Android Guide,我应该覆盖他们的getItemView方法来自定义我的行项。这是代码

public View getItemView(ParseObject object, View v, ViewGroup parent) {
    super.getItemView(object, v, parent);
    if (v == null) {
    v = View.inflate(getContext(), R.layout.adapter_item, null);
  }


  TextView descriptionView = (TextView) v.findViewById(R.id.description);
  descriptionView.setText(object.getString("description"));
  return v;
}

返回的错误是:The method getItemView is not defined for the type Activity

3 个答案:

答案 0 :(得分:1)

您应该扩展ParseQueryAdapter并在那里覆盖不在活动中的getItemView。 getItemView是来自ParseQueryAdapter而不是来自Activity

的方法

答案 1 :(得分:0)

像这样创建适配器类

public class ParseAdapter extends ParseQueryAdapter<ParseObject> 
{
 private Activity activity;
public ParseAdapter(Activity act,
        com.parse.ParseQueryAdapter.QueryFactory<ParseObject> queryFactory) {
    super(act, queryFactory);
    this.activity = act;
    // setPaginationEnabled(false);
    setObjectsPerPage(2);
    setAutoload(true);
}



@Override
public View getItemView(ParseObject object, View convertView,ViewGroup parent) {
    final ViewHolder holder;
    View vi = convertView;
    if (vi == null) {
        holder = new ViewHolder();
        inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        vi = inflater.inflate(R.layout.cus_show_new, null, false);

--------------

-----------

-------------
vi.setTag(holder);
    }

    else {
        holder = (ViewHolder) vi.getTag();

    }

return vi;
}

答案 2 :(得分:0)

根据这个Parse教程https://parse.com/tutorials/parse-query-adapter,您应该将ParseQueryAdapter子类化。