For the first time I create my own class. When you access it, the application crashes. Help me find a problem, I am probably doing something wrong because of inexperience. Class assignment: must activate or deactivate scrolling, modification of ScrollView. Created a new file in the src / com.packagename folder named LockableScrollView.java:

package com.packagename; import android.content.Context; import android.view.MotionEvent; import android.widget.ScrollView; class LockableScrollView extends ScrollView { public LockableScrollView(Context context) { super(context); // TODO Auto-generated constructor stub } private boolean mScrollable = true; public void setScrollingEnabled(boolean enabled) { mScrollable = enabled; } public boolean isScrollable() { return mScrollable; } @Override public boolean onTouchEvent(MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: if (mScrollable) return super.onTouchEvent(ev); return mScrollable; // mScrollable is always false at this point default: return super.onTouchEvent(ev); } } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!mScrollable) return false; else return super.onInterceptTouchEvent(ev); } } 

I write in xml

 <com.packagename.LockableScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scroll" android:layout_width="match_parent" android:layout_height="wrap_content"> ... ... </com.packagename.LockableScrollView> 

In the code when creating an activity, I appeal to the class to disable scrolling:

 ((LockableScrollView)findViewById(R.id.scroll)).setScrollingEnabled(false); 

Eclipse does not find any errors, but when calling this activity, a message pops up saying that the application is stopped. Help to understand, please.

  • maybe you can run the departing code under the debugger? or add a logging / debug print to localize the problem? - VladD

1 answer 1

The problem was solved after adding the class to the code

 LockableScrollView(Context context, AttributeSet attrs) 

and

 LockableScrollView(Context context, AttributeSet attrs, int defStyle): 

Happened:

 class LockableScrollView extends ScrollView { public LockableScrollView(Context context) { super(context); // TODO Auto-generated constructor stub } public LockableScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public LockableScrollView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } 
  • Please close the question if you answered it correctly. - Raskilas
  • Something I can not find the "close" button. Only edit and delete ... - Tuhlom