Hi i am currently working on an android application in it has list view inside the main activity. What i want is disable the scrolling of list and allow the whole page to scroll only,is there any way for that please do help.....
I tried with below methods but throwing "java.lang.NullPointerException:
i'm using this in Android studio IDE
Method 1 used by me ::
ViewGroup.LayoutParams listViewParams = (ViewGroup.LayoutParams)listView.getLayoutParams();
listViewParams.height = 400 + (listView.getDividerHeight()* (listView.getCount() - 1));
int height = 0;
for (int i = 0; i < listView.getChildCount(); i++) {
height += listView.getChildAt(i).getMeasuredHeight();
height += listView.getDividerHeight();
}
Log.w("Height",""+ listView.getHeight()+ height);
listViewParams.height = listView.getHeight()+ height;
listView.requestLayout();
Exception trowing :
ava.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()' on a null object reference
Method 2 used by me :
ListAdapter myListAdapter = myListView.getAdapter();if (myListAdapter == null) { //do nothing return null return;
}
//set listAdapter in loop for getting final sizeint totalHeight = 0;
for (int size = 0; size < myListAdapter.getCount(); size++) {
View listItem = myListAdapter.getView(size, null, myListView);
listItem.measure(0,0); totalHeight += listItem.getMeasuredHeight();
}
//setting listview item in adapterViewGroup.LayoutParams params = myListView.getLayoutParams();
params.height = totalHeight + (myListView.getDividerHeight() * (myListAdapter.getCount() - 1));
myListView.setLayoutParams(params);
// print height of adapter on log
Log.i("height of listItem:", String.valueOf(totalHeight));
Exception trowing :
'void android.view.View.measure(int, int)' on a null object reference
3 Answer(s)