0
RecyclerView recyclerView;
MyAdapter mAdapter;
List<ItemData> itemsData;
Global glb;
LinearLayoutManager llm;

private int valData() {
    String tmpStr;
    Cursor c;
    int position=0;
enter code here
    AutoCompleteTextView tTbl = (AutoCompleteTextView) findViewById(R.id.tblNam);
    tmpStr = tTbl.getText().toString();
    c = db.rawQuery("SELECT * FROM tblDts WHERE tblNam = '" + tmpStr + "'", null);
    if (c.getCount() == 0) {
        showMessage("Error", "Table Name Not Found");
        c.close();
        tTbl.requestFocus();
        return 1;
    }
    c.close();

    for (int i = 0; i < itemsData.size(); i++) {
        tmpStr = itemsData.get(i).getTitle().toString();
        c = db.rawQuery("SELECT * FROM itmDts WHERE itmNam = '" + tmpStr + "';", null);
        if (c.getCount() == 0) {

            c.close();

            //llm.scrollToPositionWithOffset(i,0);
            //recyclerView.smoothScrollToPosition(i);
            //recyclerView.scrollToPosition(i);

i tried all the above scroll procedure, when i using getChildAt its return only view of the before scroll and not the new one

            //View vw = llm.getChildAt(0);
            tmpStr="";

when rise the findviewholderforadapterpostion in between current display views there has been it shows correctly but if i rise non display position it returns null RecyclerView.ViewHolder vh = recyclerView.findViewHolderForAdapterPosition(i); View vw = vh.itemView;

            AutoCompleteTextView tTa=(AutoCompleteTextView)vw.findViewById(R.id.item_title);
            tmpStr =tTa.getText().toString();


            showMessage(llm.getChildCount()+"Error" + position, "Item Name Not Found" + tmpStr);

            //recyclerView.setLayoutManager(lm);


            return 1;
        }
        c.close();

    }
    return 0;
}


   }
}
Saran
  • 1
  • 1
  • 2
  • did you resolve this problem? – Gintama Sep 10 '15 at 07:23
  • recyclerView.setItemViewCacheSize(0) refer: [https://stackoverflow.com/questions/37885863/onbindviewholder-is-never-called-on-view-at-position-even-though-recyclerview](https://stackoverflow.com/questions/37885863/onbindviewholder-is-never-called-on-view-at-position-even-though-recyclerview) – afunx Aug 14 '17 at 11:45
  • recyclerView.setItemViewCacheSize(0) [refer](https://stackoverflow.com/questions/37885863/onbindviewholder-is-never-called-on-view-at-position-even-though-recyclerview) – afunx Aug 14 '17 at 11:47

1 Answers1

0

I am always facing with these kind of problems on Android platform. And most of my problems fixed with thread sleep :) This is not a proper way but could not found any other way. Just you need to add 100 ms sleep after scrolled the next item.

Following code is for Xamarin.Android.

public async static void FocusNextItem(Android.Support.V7.Widget.RecyclerView recyclerView, int nextPosition)
    {
        recyclerView.ScrollToPosition(nextPosition);

        var viewHolder = recyclerView.FindViewHolderForAdapterPosition(nextPosition);
        if (viewHolder == null)
        {
            await System.Threading.Tasks.Task.Delay(100);

            viewHolder = recyclerView.FindViewHolderForAdapterPosition(nextPosition);
        }
        viewHolder?.ItemView?.RequestFocus();
    }
Samet KAHRAMAN
  • 147
  • 2
  • 7
  • Yes Saret, you are right but I could not find correct way to handle this kind of problems. – Samet KAHRAMAN Jun 13 '16 at 08:05
  • I am facing the exact same problem and I have also resolved to using Thread sleep. I also know that it doesn't look like a good solution but there doesn't seem to be any callback that we could use for this purpose. Have you managed to think of some other solution? – AlexSee May 03 '17 at 16:16