I am new to Android.
I have to update a ListView with chatAdapter.notifyDataSetChanged();
Everything works as expected, ListView is updated.
Then I need to call ListView getChildAt(index), however it is always null, unless I wait for some times
Here is code snippet below:
chatAdapter.notifyDataSetChanged();
if (requestType == RequestType.FirstRequest){
if (chatMessages.size() != 0) {
//scroll to bottom
chatListView.setSelection(chatMessages.size() - 1);
Log.i(TAG, "" + chatListView.getChildAt(0));
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Log.i(TAG, "" + chatListView.getChildAt(0));
}
}, 3000);
}
}
The first Log always returns null, however, I am able to get child if I wait 3 seconds. It seemed that after I called chatAdapter.notifyDataSetChanged(), it took some time to inflate those child views. How do I properly call getChildAt(index) in this case?