【问题标题】:getAdapterPosition() is not a methodgetAdapterPosition() 不是方法
【发布时间】:2015-07-28 09:50:06
【问题描述】:

在我的新 Android 项目中,当我想获取 RecyclerView 中的当前位置时,我遇到了以下问题:

无法解析方法“getAdapterPosition()”

在我的其他 Android Studio 项目中,一切正常。

    public static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
    protected TextView itemName;
    protected ImageView itemIcon;

    public MyViewHolder(View v, UserClickListener listener) {
        super(v);
        // a- A
        mListener = listener;

        itemName = (TextView) v.findViewById(R.id.rowText);
        itemIcon = (ImageView) v.findViewById(R.id.rowIcon);

        v.setOnClickListener(this);
    }

    public void onClick(View v) { mListener.onClick(v, getAdapterPosition()); }
}

在 build.gradle 我有这个:

compile 'com.android.support:recyclerview-v7:21.0.3'

【问题讨论】:

    标签: android android-studio android-recyclerview


    【解决方案1】:

    getAdapterPosition() 是支持库 v22 的一部分,因此使用它的唯一方法是升级它。在这里你可以找到changelog

    【讨论】:

    • 谢谢。在另一个项目中,它使用的是 v21。我可以设置 Android Studio 在库有新更新时发送通知吗?谢谢。
    • 这是一个 gradle 的东西,不仅仅是一个 android-studio。您可以使用 gradle 始终获取支持库的最后一个可用版本。但强烈建议不要这样做
    • @SaschaK。有关 android 支持库,请访问 android-developers.blogspot.cz 以获取更新。
    猜你喜欢
    • 2017-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多