O yöntemini
recyclerView.findViewHolderForAdapterPosition(pos).itemView.performClick();
kullanmak titiz tarafından hoş karşılanmaz:
Return the ViewHolder for the item in the given position of the data set. Unlike
* {@link #findViewHolderForLayoutPosition(int)} this method takes into account any pending
* adapter changes that may not be reflected to the layout yet. On the other hand, if
* {@link Adapter#notifyDataSetChanged()} has been called but the new layout has not been
* calculated yet, this method will return <code>null</code> since the new positions of views
* are unknown until the layout is calculated.
bir iplikle geciktirmede bazen yararlı olduğunu tam olarak nedenle. NotifyDataSetChanged() öğesine yapılan herhangi bir çağrı, null döndürmesine neden olur. Bağdaştırıcı yöntemini onBindViewHolder'da kullanmak ve konum 0'ı kontrol etmek daha iyidir. Dinleyicinizi nasıl ayarlayacağınıza göre ayarlama yapın, örneğin ViewHolder yapıcısında oluşturulan usual way örneğidir. yine aradı engellemek için init değişkeni kullanın:
@Override
public void onBindViewHolder(FooAdapter.ViewHolder viewHolder, int position) {
//code
...
//do this last especially if you are using an animator
if(position == 0 && isInit) {
listener.onItemClick(viewHolder.itemView,0);
isInit =false;
}
}
kullanmak pozisyonda üst üste içine belirli bir görünümünü tıklayın isterseniz? – Gaket
Bazen boş bir işaretçi istisnası verdiği için tıklama etkinliğinde 1 ms gecikme. – Saurabh
Bu çocuk doğru ... çözülmüş null pointer istisnası –