I have a relativeLayout above my listView. And the relativeLayout moves up at the same time as the listView is scrolling up. For example If the relativeLayout height is 500px, the listView padding becomes 500px and the relativeLayout stays in the padding part. When list view is scrolled up the relativeLayout goes up also in the same pixels.
Everything works fine if the listView items are created. However if the relativeLayout height is higher than the visible area, the padding becomes so high that the listView items are not created. Because only visible part of the list view is created by calling getView. And scrolling up is not working as there are no items in the list.
So if I can load also non-visible items that are below the padding area everything would work fine. Is there anyway to do this or create the getView call manually with a for loop?
Below is the code that I use.
private void reloadData() {
adapter = new MyListAdapter();
list = (ListView) view.findViewById(R.id.fragment_commenters_myListView);
list.setAdapter(adapter);
list.setPadding(0, movingRelativeayout.getHeight(), 0, 0);
list.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
this.isScrollCompleted();
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
if (list.getChildAt(0) != null) {
View listChildView = list.getChildAt(0);
int scrollPosition = -listChildView.getTop() + list.getFirstVisiblePosition() * listChildView.getHeight();
if (scrollPosition < 5000) {
RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) movingRelativeayout.getLayoutParams();
params1.setMargins(Math.round(0 * dipToPixel), Math.round(-scrollPosition) - movingRelativeayout.getHeight(), Math.round(0 * dipToPixel), Math.round(0 * dipToPixel));
movingRelativeayout.setLayoutParams(params1);
}
}
}
private void isScrollCompleted() {
}
});
}
private class MyListAdapter extends ArrayAdapter<String> {
public MyListAdapter() {
super(getActivity().getApplicationContext(), R.layout.fragment_commenters_cell, myItemList);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View cellView = convertView;
if (cellView == null){
cellView = getActivity().getLayoutInflater().inflate(R.layout.fragment_commenters_cell, parent, false);
}
cellProfileBtn = (Button) cellView.findViewById(R.id.fragment_commenters_cell_profileBtn);
cellProfileImage = (ImageView) cellView.findViewById(R.id.fragment_commenters_cell_profileImg);
cellProfileImage.setImageBitmap(resultsImageBitmapFiles.get(position));
cellProfileBtn.setText(resultsNameArray.get(position));
return cellView;
}
}