ExpandableListView inside RecyclerView inside a ViewPager - android

I'm facing problems in scrolling. I've the following structure in order in my project:
1) ViewPager
2) RecyclerView
3) ExpandableListView
I cannot scroll the ExpandableListView; but I can scroll RecyclerView. I tried setNestedScrolling but i didn't work.
Any solutions?

I think what you need to do is disable the scroll of the parent when you touch the child. So this should work
mListView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
//Disallow the touch request for parent scroll on touch of child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});

Related

Differentiate touch events between customView and scroll view

I have one customView and customView added in scroll view. Now i want differentiate both touch events. My problem is when try to scroll, customView also getting touch event and when i try to change in customView, scroll view getting events.
How can we stop customView touch event when scrolling.
How can we stop scroll touch events when customView wants events.
Thanks in advance
You can set touch listener to child view and then in onTouch() event, you can block intercept touch event of parent.
i.e.
v.setOnTouchListener(new OnTouchListener() {
// Setting on Touch Listener for handling the touch inside ScrollView
#Override
public boolean onTouch(View v, MotionEvent event) {
// Disallow the touch request for parent scroll on touch of child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
About the second question, I don't know exactly what you're doing with customview but maybe you'd like to use click events instead because it's rather not user friendly to use different logic in ontouch and onclick as it will always fire up unexpectedly.
boolean isScrolling = false;
myScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() { #Override public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY)
isScrolling = scrollX != oldScrollX;
//for vertical scrolling
});
//then onTouchListener
if(!isScrolling){//Do operations on non scrolled state}

Nested vertical RecyclerViews

I have an issue making 2 nested vertical RecyclerViews. I know this isn't a great pattern, but these are the application requests.
I have a parent RecyclerView, and when a card expands it should scroll to top and in the expanded part, I have another RecyclerView (a list of locations).
The problem is that I couldn't pass the scroll event from the parent, to the child RecyclerView. I read about the NestedScrollingChild interface and tried to enable nestedScrolling in child, but with no success.
Any suggestions?
I fixed it by adding the following code on my main RecyclerView adapter. Works perfectly.
holder.locationsList.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
Log.v(TAG, "CHILD TOUCH");
// Disallow the touch request for parent scroll on touch of child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});

show one Recyclerview item at a time - Android

My Recyclerview item occupies the whole screen height and width.
I wish to implement a custom scroll inside the Recyclerview such that it scrolls only one item at a time ( similar to News In Shorts app ).
Thanks in advance!!
You need to add just two below Lines
RecylerView mRecylerView = (RecylerView).findViewById(R.id.mRecylerView)
SnapHelper mSnapHelper = new PagerSnapHelper();
mSnapHelper.attachToRecyclerView(mRecylerView);
SnapHelper can be used to snap the child to any imaginary point or any pixel on the screen
Try this code
parentScrollView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
findViewById(R.id.childScrollView).getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});
childScrollView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// Disallow the touch request for parent scroll on touch of
// child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});

ScrollView inside PullToRefreshScrollView does not scroll

Well I have in the main_layout a pulltorefresh viewgroup inside of that layout I have two fragments - One of these fragments has a ScrollView layout - so basically one fragment has an image and the other is scrollable with a bunch of details. I use this code to disable the pulltorefresh from intercepting the touch events that are made on the scrollable fragment part:
descriptionScrollView = (ScrollView) findViewById(R.id.detail_item_description_holder_scroller);
descriptionScrollView
.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
// Disallow the touch request for parent scroll on
// touch of child view
descriptionScrollView
.requestDisallowInterceptTouchEvent(false);
pullToRefreshScrollView.getRefreshableView()
.requestDisallowInterceptTouchEvent(true);
return false;
}
});
This blocks the pulltorefresh from scrolling when I touch on the scrollview part of the screen - the only problem is that the scrollview layout is not scrollable at all. When I remove the PulltoRefresh from my main_layout this scrollview from fragments layout becomes scrollable..
Please help

Is there any way to scroll the scrollbar of gridview/listview inside Scrollview?

Hi in my application the screen is so large which contains a gridview with images and listview with lot of list items and also so many text views existed in my screen. so that i placed this content in scrollview to view on the mobile screen. When I placed the content in the scrollview then the gridview/listview scroll is not working.
Is there any way to solve this issue. I referred so many links but i could not get the solution.
The links are
Grid of images inside ScrollView
How can I put a ListView into a ScrollView without it collapsing?
etc
You can solve it using following code, but I suggest please change UI, it is not according android guideline. it' easily scrolled in iPhone interface.
final ScrollView childScroll = (ScrollView)
view.findViewById(R.id.resourceactivity_sv_classes_detail);
parentScroll.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
//Log.v(TAG,"PARENT TOUCH");
childScroll.getParent().requestDisallowInterceptTouchEvent
(false); return false; } }); childScroll.setOnTouchListener(new
View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
//Log.v(TAG,"CHILD TOUCH");
v.getParent().requestDisallowInterceptTouchEvent(true); return
false; } });
You can modify gridview instead of child scrollview.

Categories

Resources