У меня есть собственный ViewPager внутри моего ExpandableListView, прослушиватель кликов не срабатывает, есть ли идея, как это сделать? Я знаю, что я могу добавить слушателя кликов внутри адаптера, но я бы предпочел.ViewPager внутри ExpandableListView click Listener не работает
обычай пейджера
public class CustomPager extends ViewPager {
/**
* the last x position
*/
private float lastX;
/**
* if the first swipe was from left to right (->), dont listen to swipes from the right
*/
private boolean slidingLeft;
/**
* if the first swipe was from right to left (<-), dont listen to swipes from the left
*/
private boolean slidingRight;
public CustomPager(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
public CustomPager(final Context context) {
super(context);
}
@Override
public boolean onTouchEvent(final MotionEvent ev) {
final int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow parent ViewPager to intercept touch events.
this.getParent().requestDisallowInterceptTouchEvent(true);
// save the current x position
this.lastX = ev.getX();
break;
case MotionEvent.ACTION_UP:
// Allow parent ViewPager to intercept touch events.
this.getParent().requestDisallowInterceptTouchEvent(false);
// save the current x position
this.lastX = ev.getX();
// reset swipe actions
this.slidingLeft = false;
this.slidingRight = false;
break;
case MotionEvent.ACTION_MOVE:
/*
* if this is the first standing_item, scrolling from left to
* right should navigate in the surrounding ViewPager
*/
if (this.getCurrentItem() == 0) {
// swiping from left to right (->)?
if (this.lastX <= ev.getX() && !this.slidingRight) {
// make the parent touch interception active -> parent pager can swipe
this.getParent().requestDisallowInterceptTouchEvent(false);
} else {
/*
* if the first swipe was from right to left, dont listen to swipes
* from left to right. this fixes glitches where the user first swipes
* right, then left and the scrolling state gets reset
*/
this.slidingRight = true;
// save the current x position
this.lastX = ev.getX();
this.getParent().requestDisallowInterceptTouchEvent(true);
}
} else
/*
* if this is the last standing_item, scrolling from right to
* left should navigate in the surrounding ViewPager
*/
if (this.getCurrentItem() == this.getAdapter().getCount() - 1) {
// swiping from right to left (<-)?
if (this.lastX >= ev.getX() && !this.slidingLeft) {
// make the parent touch interception active -> parent pager can swipe
this.getParent().requestDisallowInterceptTouchEvent(true);
} else {
/*
* if the first swipe was from left to right, dont listen to swipes
* from right to left. this fixes glitches where the user first swipes
* left, then right and the scrolling state gets reset
*/
this.slidingLeft = true;
// save the current x position
this.lastX = ev.getX();
this.getParent().requestDisallowInterceptTouchEvent(true);
}
}
break;
}
super.onTouchEvent(ev);
return true;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int height = 0;
for(int i = 0; i < getChildCount(); i++)
{
View child = getChildAt(i);
child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int h = child.getMeasuredHeight();
if(h > height) height = h;
}
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
надувать его в моей adapater
if (groupPosition == 0) {
final HeaderHolder viewHolder;
convertView = mInflater.inflate(R.layout.season_team_fixtures_item, null);
viewHolder = new HeaderHolder();
viewHolder.customIndicator = (CircleIndicator) convertView.findViewById(R.id.indicator_custom);
viewHolder.viewPager = (CustomPager) convertView.findViewById(R.id.pager);
viewHolder.seeAll = (TextView) convertView.findViewById(R.id.AllFixtures);
viewHolder.viewPager.setAdapter(adapter);
viewHolder.customIndicator.setViewPager(itemView.viewPager);
season_team_fixtures_item layot
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/appBackground">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp">
<ProgressBar
android:id="@+id/linlaHeaderProgress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:indeterminate="true"
android:indeterminateDrawable="@drawable/progress_drawable"
android:visibility="gone" />
<LinearLayout
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:descendantFocusability="blocksDescendants"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<com.redeagle07.egyptianleague.teams.season.CustomPager
android:id="@+id/pager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/white_frame"
android:descendantFocusability="blocksDescendants"
android:focusable="true"
android:focusableInTouchMode="true" />
<me.relex.circleindicator.CircleIndicator
android:id="@+id/indicator_custom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="4dp"
android:background="@android:color/white"
app:ci_animator="@animator/indicator_animator"
app:ci_animator_reverse="@animator/indicator_animator_reverse"
app:ci_drawable="@drawable/black_radius_square" />
<TextView
android:id="@+id/AllFixtures"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/white_frame"
android:gravity="end"
android:paddingLeft="2dp"
android:textColor="@color/ColorPrimaryDark"
android:paddingRight="2dp"
android:text="@string/Allfixtures"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="15sp" />
</LinearLayout>
</android.support.v7.widget.CardView>
Цените помощь ребята, спасибо заранее
посмотрите на следующий пример, это работает: http://stackoverflow.com/questions/24083886/ expandablelistview-в-фрагмент-выпуск/24159659 # 24159659. Пожалуйста, поддержите ответ, если он поможет вам. –
@codedByMi Вы понимаете различия между * ViewPager внутри ExpandableListView * и * ExpandableListView внутри ViewPager * – Selvin
Я просто пытался помочь –