我想看看我在recyclerview上滚动的位置

时间:2018-02-13 13:50:04

标签: java android

我有一个活动及其相关的适配器。当我将一个列表传递给我的适配器时,在onBindViewHolder中我放了一个日志,每当我滚动我的Recyclerview时,我都能看到我确切的位置。滚动;我没有问题。 但我有另一个类和它的相关适配器,这两个适配器是相似的。但在第二个recyclerview我不能看到我滚动的位置; Logcat一次向我显示所有位置。

我将向您展示myclasses及其相关适配器: 首先(没有问题):

public class adapteeer extends RecyclerView.Adapter<adapteeer.RecyclerViewHolder> {

private MyActivity mContext;
public static ArrayList<Question> questionlist;

public adapteeer(MyActivity context, ArrayList<Question> objects) {

    mContext = context;
    questionlist = objects;
    ...
}

@Override
public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(mContext).inflate(R.layout.question_items_activity, parent, false);
    RecyclerViewHolder gridViewHolder = new RecyclerViewHolder(view);
    return gridViewHolder;
}

public class RecyclerViewHolder extends RecyclerView.ViewHolder {

    ....

    public RecyclerViewHolder(View view) {
        super(view);
       ....
    }
}

@Override
public void onBindViewHolder(final RecyclerViewHolder holder, final int position) {

    Log.e("possssss", position + "");

}

@Override
public int getItemCount() {
    return questionlist.size();
}
}

和此适配器的Logcat:

02-13 11:44:19.663 22463-22463/com.example.qa E/possssss: 0
02-13 11:44:19.738 22463-22463/com.example.qa E/possssss: 1

因为我只能看到2行的recyclerview。

另一个适配器:(一次给我所有位置)

public class RecyclerViewAdapterUnseenNoti extends RecyclerView.Adapter<RecyclerViewAdapterUnseenNoti.RecyclerViewHolder> {

private Context mContext;
private ArrayList<Notification> notilist;

public RecyclerViewAdapterUnseenNoti(Context context, ArrayList<Notification> objects) {
    mContext = context;
    notilist = objects;
}

@Override
public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(mContext).inflate(R.layout.notification_items_activity, parent, false);
    RecyclerViewHolder gridViewHolder = new RecyclerViewHolder(view);
    return gridViewHolder;
}


public class RecyclerViewHolder extends RecyclerView.ViewHolder {

   ...

    public RecyclerViewHolder(View view) {
        super(view);

       ...
    }

}

@Override
public void onBindViewHolder(final RecyclerViewHolder holder, final int position) {

    Log.e("possssss", position + "");

    final Notification notification = notilist.get(position);
    ....
}

@Override
public int getItemCount() {
    return notilist.size();
}
}

但是对于这个适配器,Logcat向我展示了fisrt的所有位置:(虽然我只能在屏幕上看到3个列表项目)

02-13 14:16:09.865 22316-22316/com.example.qa E/possssss: 0
02-13 14:16:09.900 22316-22316/com.example.qa E/possssss: 1
02-13 14:16:09.920 22316-22316/com.example.qa E/possssss: 2
02-13 14:16:09.940 22316-22316/com.example.qa E/possssss: 3
02-13 14:16:09.960 22316-22316/com.example.qa E/possssss: 4
02-13 14:16:09.980 22316-22316/com.example.qa E/possssss: 5
02-13 14:16:10.005 22316-22316/com.example.qa E/possssss: 6
02-13 14:16:10.030 22316-22316/com.example.qa E/possssss: 7
02-13 14:16:10.065 22316-22316/com.example.qa E/possssss: 8
02-13 14:16:10.090 22316-22316/com.example.qa E/possssss: 9

我不知道为什么!

0 个答案:

没有答案