0

以下の拡張された linearlayout は、SimpleGestureListener を使用してスワイプ イベントを検出します。

public class MyLinearLayout extends LinearLayout implements SimpleGestureListener {
private SimpleGestureFilter detector;
private SwipeEvent listener;

@SuppressLint("NewApi")
public MyLinearLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    detector = new SimpleGestureFilter((Activity) context, this);
    // TODO Auto-generated constructor stub
}

public MyLinearLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    detector = new SimpleGestureFilter((Activity) context, this);
    // TODO Auto-generated constructor stub
}

public MyLinearLayout(Context context) {
    super(context);
    detector = new SimpleGestureFilter((Activity) context, this);

    // TODO Auto-generated constructor stub
}

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    // TODO Auto-generated method stub
    this.detector.onTouchEvent(ev);
    boolean ret = super.dispatchTouchEvent(ev);
    Log.e("MLL","ret = "+String.valueOf(ret));
    return /*super.dispatchTouchEvent(ev);*/ ret;
}
/*@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    // TODO Auto-generated method stub
    this.detector.onTouchEvent(ev);
    return super.onInterceptTouchEvent(ev);
}*/

@Override
public void onSwipe(int direction) {
    // TODO Auto-generated method stub

    Log.e("LinearLayout","Inside onSwipe");
    switch (direction) {

    case SimpleGestureFilter.SWIPE_RIGHT:
//      Toast.makeText(getContext(), "Swipe Right", Toast.LENGTH_SHORT).show();
        listener.onRightSwipe();

        break;
    case SimpleGestureFilter.SWIPE_LEFT:
//      Toast.makeText(getContext(), "Swipe SWIPE_LEFT", Toast.LENGTH_SHORT).show();
        listener.onLeftSwipe();

        break;
    case SimpleGestureFilter.SWIPE_DOWN:
//      Toast.makeText(getContext(), "Swipe SWIPE_DOWN", Toast.LENGTH_SHORT).show();
        listener.onDownSwipe();
        //TODO As playerControls becomes null on each orientation switch, let's change playerControls to playerControlFragments

        break;
    case SimpleGestureFilter.SWIPE_UP:
//      Toast.makeText(getContext(), "Swipe SWIPE_UP", Toast.LENGTH_SHORT).show();
        listener.onUpSwipe();

        break;

    }

}

@Override
public void onDoubleTap() {
    // TODO Auto-generated method stub

}
static public interface SwipeEvent {
    public void onRightSwipe();
    public void onLeftSwipe();
    public void onDownSwipe();
    public void onUpSwipe();
}
public void setSwipeEventListener(SwipeEvent listener) {
    // TODO Auto-generated method stub
    this.listener = listener;

}

}

問題は、このレイアウトに配置された Imagebutton の Onclick リスナーを使用できないことです

<com.example.player.MyLinearLayout
        android:id="@+id/details"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="5dip"
        android:orientation="vertical"
        android:animateLayoutChanges="true"
        android:descendantFocusability="afterDescendants"
        android:padding="3dip" >
        <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="5dip"
        android:orientation="horizontal"
        android:animateLayoutChanges="true"
        android:padding="3dip"
            >
            <TextView
            android:id="@+id/firstTitle"
            android:layout_width="0dip"
            android:layout_weight="0.8"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:ellipsize="marquee"
            android:singleLine="true"
            android:text="First"
            android:clickable="true"
            android:textAppearance="?android:attr/textAppearanceMedium" />

            <ImageButton
                android:id="@+id/hideControl"
                android:layout_weight="0.2"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginLeft="12dp"
                android:background="@android:color/transparent"
                android:rotation="90"
                android:src="@drawable/hide"
                android:clickable="true"

                 />

        </LinearLayout>


        <View
            android:layout_width="match_parent"
            android:layout_height="2dip" />

        <TextView
            android:id="@+id/secondTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="left|bottom"
            android:text="Second"
            android:clickable="true"
            android:textAppearance="?android:attr/textAppearanceSmall" />
    </com.example.player.MyLinearLayout>

hideControls を聞いていますが、呼び出されない理由がわかりません...

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
//      Log.e(TAG, "Inside fragment'sonCreateView");
    View rootView = inflater.inflate(R.layout.frag_layout,
            container, false);
hideControl = (ImageButton) rootView.findViewById(R.id.hideControl);
    hideControl.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

                Log.e(TAG,"PlayerControl clicked via listener");

        }
    });

どこに次のようなものがfrag_layout.xml含まれていますMyLinearLayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:animateLayoutChanges="true"
    android:orientation="horizontal" >

    <LinearLayout
        ... >

    </LinearLayout>
    <com.example.player.MyLinearLayout
        ... />
    </com.example.player.MyLinearLayout>
</LinearLayout>

<RelativeLayout
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:animateLayoutChanges="true"
    android:orientation="horizontal" >

    ...

</RelativeLayout>


<LinearLayout
    ... />

</LinearLayout>

4

0 に答える 0