Does a View that can handle adapters (e.g. ArrayAdapter) but is not scrollable exist?
I would not like to go into workarounds (e.g. disabling a ListView's scrolling feature).
Does a View that can handle adapters (e.g. ArrayAdapter) but is not scrollable exist?
I would not like to go into workarounds (e.g. disabling a ListView's scrolling feature).
Sure you can. Calling getView
on an adapter returns a View
that corresponds to the information provided from the adapter's getItem
method. So you can do something like this:
LinearLayout layout = (LinearLayout) view.findViewById(R.id.linear_layout);
BaseAdapter adapter = new CustomAdapter(context, itemList);
for (int i = 0; i < itemList.size(); i++) {
// you can pass in a recycled view instead of null
View itemView = adapter.getView(i, null, layout);
layout.addView(itemView);
}
ViewGroups such as LinearLayout
aren't scrollable by themselves so this should work. I'm not sure why you would want to use an Adapter
in this situation but that's up to you.
You can use the following or refer to the mentioned links
listView.setScrollContainer(false);
References : Disable scrolling of a ListView contained within a ScrollView
// try this wau
1. Create your custom Listview like below and use it rather default ListView
public class MyCustomListView extends ListView {
@SuppressWarnings("unused")
private static final int SWIPE_MIN_DISTANCE = 50;
@SuppressWarnings("unused")
private static final int SWIPE_THRESHOLD_VELOCITY = 100;
@SuppressWarnings("unused")
private GestureDetector gDetector;
@SuppressWarnings("unused")
private boolean isFling;
private float mDiffX;
private float mDiffY;
private float mLastX;
private float mLastY;
/**
* Overrides method
*/
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
// reset difference values
mDiffX = 0;
mDiffY = 0;
mLastX = ev.getX();
mLastY = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
final float curX = ev.getX();
final float curY = ev.getY();
mDiffX += Math.abs(curX - mLastX);
mDiffY += Math.abs(curY - mLastY);
mLastX = curX;
mLastY = curY;
// don't intercept event, when user tries to scroll vertically
if (mDiffX > mDiffY) {
return false; // do not react to horizontal touch events, these
// events will be passed to your list item view
}
}
return super.onInterceptTouchEvent(ev);
}
public MyCustomListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context);
}
public MyCustomListView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public MyCustomListView(Context context) {
super(context);
init(context);
}
private void init(Context mContext) {
}
}