Я пытаюсь создать ListView внутри Viewpager. ViewPager использует Fragements. Поэтому ListView находится внутри Fragement. Мой список не прокручивается, хотя в Listview onitmclicked и ontouch вызывается.
Мой код
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:app1="http://schemas.android.com/apk/res/com.bookthefield.user"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tabHost"
android:focusableInTouchMode="false" />
<utilities.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="48dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="@color/white"
app1:pstsIndicatorColor="@color/available"
app1:pstsShouldExpand="true" >
</utilities.PagerSlidingTabStrip>
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#d8d7dd" >
<ListView
android:id="@+id/lvalltourney"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:divider="#d8d7dd"
android:dividerHeight="10dp" >
</ListView>
</RelativeLayout>
lvalltourney.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
lvalltourney.getParent().requestDisallowInterceptTouchEvent(
true);
int action = event.getActionMasked();
switch (action) {
case MotionEvent.ACTION_UP:
lvalltourney.getParent()
.requestDisallowInterceptTouchEvent(false);
break;
}
return false;
}
});
Код адаптера
class tourneyadapter extends BaseAdapter {
private Context mContext;
private final ArrayList<tourney> tourneylist;
public tourneyadapter(Context c, ArrayList<tourney> tourneylist) {
mContext = c;
this.tourneylist = tourneylist;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return tourneylist.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
View grid; //
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
grid = new View(mContext);
grid = inflater.inflate(R.layout.tourneylistingitem, null);
} else {
grid = (View) convertView;
}
final tourney temp = tourneylist.get(position);
TextView tvtourneyname = (TextView) grid
.findViewById(R.id.tvtourneyname);
tvtourneyname.setText(temp.getName());
TextView tvlocationname = (TextView) grid
.findViewById(R.id.tvlocationtourney);
tvlocationname.setText(temp.getAddress());
TextView tvdatetourney = (TextView) grid
.findViewById(R.id.tvdatetourney);
tvdatetourney.setText(temp.getDate());
try {
TextView tvcost = (TextView) grid
.findViewById(R.id.tventeryfee);
tvcost.setText(temp.getEntryfee() + " ");
ImageView imagesport = (ImageView) grid
.findViewById(R.id.imagesport);
imagesport.setImageResource(temp.getDrawable());
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return grid;
}
}
ОБНОВЛЕНИЕ: 1
Я расширил свой Viewpager и использовал его в xml и javacode
public class MyViewPager extends ViewPager {
private GestureDetector mGestureDetector;
View.OnTouchListener mGestureListener;
public MyViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
mGestureDetector = new GestureDetector(context, new YScrollDetector());
setFadingEdgeLength(0);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return super.onInterceptTouchEvent(ev)
&& mGestureDetector.onTouchEvent(ev);
}
// Return false if we're scrolling in the x direction
class YScrollDetector extends SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
return Math.abs(distanceY) > Math.abs(distanceX);
}
}
}