0

I am extending a Fragment called Scanlist. It is laid out properly and looks how I want it. Problem is I am unable to Override onInterceptTouchEvent on the extended Fragment. So I thought of extending ViewGroup, Override onInterceptTouchEvent and then add my Fragment to the ViewGroup. When I add my Fragment to the ViewGroup the Fragment is not showing up inside the ViewGroup. I know the ViewGroup is there because I am able to Log the onInterceptTouchEvent but the screen is blank.

Here is the Fragment:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mRootview = (ViewGroup) inflater.inflate(R.layout.scanlist, container, false);
    mRootview.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    mSharedData = new SharedData(mContext);
    costomListViewArr = mSharedData.getvins();
    Resources res = getResources();

    mList = (ListView)mRootview.findViewById(R.id.list);
    mAdapter = new Scanvinadapter(mActivity, costomListViewArr, res);

    mList.setAdapter(mAdapter);
    mAdapter.setimplements(this);

    ViewGroup vg = new Scanlistview(mContext);
    vg.addView(mRootview);
    return vg;
}

Here is the ViewGroup

public class Scanlistview extends ViewGroup{
    @SuppressWarnings("unused")
    private final String TAG = this.getClass().getSimpleName();
    LayoutInflater mInflater;
    public Scanlistview(Context context) {
        super(context);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev){
        Log.v(TAG, "onInterceptTouchEvent");
        return false;
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {

    }
}

scanlist.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/flScanlist"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background="@drawable/vinlist_bg">
        <ListView
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" 
            android:background="@drawable/vinlist_selector"
            android:listSelector="@drawable/vinlist_selector"/>
</FrameLayout>
K3NN3TH
  • 1,458
  • 2
  • 19
  • 31
  • why a custom ViewGroup? override onInterceptTouchEvent in a root container returned by Fragment.getView method – pskink Aug 25 '14 at 13:20
  • @pskink not sure how to do that? This gives me the root of the fragment `ViewGroup vg = (ViewGroup) mRootview.findViewById(R.id.flScanlist);` but I am not sure how to `setOnInterceptTouchEvent` on vg? – K3NN3TH Aug 25 '14 at 13:37
  • post R.layout.scanlist layout file – pskink Aug 25 '14 at 13:41
  • @pskink ive added it to my question – K3NN3TH Aug 25 '14 at 13:44
  • so instead of FrameLayout add your custom FrameLayout with overriden method – pskink Aug 25 '14 at 13:46
  • @pskink i never looked at it like that, thanks so much works liek a charm, if you want to answer this question let me know, if not I will just delete it!! – K3NN3TH Aug 25 '14 at 14:20

1 Answers1

1

instead of FrameLayout add your custom FrameLayout with overriden method, also you don't actually need that FrameLayout as it has only one child, so you can just place custom ListView in the layout file

pskink
  • 23,874
  • 6
  • 66
  • 77