In my fragment I have a TextView and underneath there are two buttons.
I need to implement a OnTouchListener to do two things:
When I rotate my two fingers, the TeXtView will rotate
When I tap the TeXtView, the buttons underneath are called
Right now it doesnt work but I cant find better solution.
XML:
<?xml version="1.0" encoding="utf-8"?>
<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"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerInParent="true"
tools:context="com.fjord.yalc.MainActivity"
android:id="#+id/player_fragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="#+id/buttonUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/transparent"/>
<Button
android:id="#+id/buttonDown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/transparent"/>
</LinearLayout>
<com.fjord.yalc.AutoResizeTextView
android:id="#+id/player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:maxLines="1"
android:text="#string/normal_start"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.DialogWindowTitle"
android:textColor="#color/colorLightGray"
android:textSize="300sp"
android:textStyle="bold"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
JAVA:
Btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
player.setText(String.valueOf(++life));
}
});
mRotationDetector = new RotationGestureDetector(this);
TV.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
int maskedAction = event.getActionMasked();
switch (maskedAction) {
case MotionEvent.ACTION_DOWN: {
return false;
}
case MotionEvent.ACTION_OUTSIDE: {
return false;
}
case MotionEvent.ACTION_MOVE: {
mRotationDetector.onTouchEvent(event);
break;
}
}
return true;
}
});
Ok, after a week I found the answer. I needed to dispatch my MotionEvent to parent of my buttons using dispatchTouchEvent. ACTION_POINTER_DOWN is for checking if user uses two fingers.
Now rotation goes to mRotationDetector and taps goes to onClickListeners of the buttons underneath the TextView player.
JAVA:
player.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
MotionEvent me = MotionEvent.obtain(event);
mRotationDetector.onTouchEvent(me);
switch (event.getActionMasked()){
case (MotionEvent.ACTION_DOWN):
flag=true;
break;
case(MotionEvent.ACTION_POINTER_DOWN):
flag=false;
break;
}
buttons.dispatchTouchEvent(event);
return true;
}
});
Related
I have problem with setOnLongClickListener. When I use this method I want the dialog, which will open, to automatically close by itself (which the method's return false should do) when I take my finger off the screen. Is it possible to do this with this method, or are there other suitable methods?
Create Dialog
protected void showDialogLongClick(final int position){
final Dialog dialog = new Dialog(activity);
dialog.setCancelable(true);
View v = activity.getLayoutInflater().inflate(R.layout.onlongclick_card_mygift,null);
dialog.setContentView(v);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
nameLong = v.findViewById(R.id.name_longclick);
descriptionLong = v.findViewById(R.id.gift_description);
addressLong = v.findViewById(R.id.gift_address);
imageCategory = v.findViewById(R.id.small_category);
nameLong.setText(myGift.get(position).getName());
descriptionLong.setText(myGift.get(position).getDescription());
addressLong.setText(myGift.get(position).getAddress());
String cat = myGift.get(position).getCategory();
changeCategoryImage(cat, imageCategory);
dialog.show();
}
Listener
holder.card.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
showDialogLongClick(position);
return false;
}
});
XML card dialog
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_gravity="center"
app:cardCornerRadius="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/background_card_mygift"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/name_longclick"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#FFFFFF"
android:textSize="25sp"
android:layout_weight="1"
android:layout_marginEnd="10dp"/>
<ImageView
android:id="#+id/small_category"
android:layout_weight="0"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#F44336"
android:textSize="22sp"/>
<TextView
android:id="#+id/gift_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#FFFFFF"
android:textSize="20sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#F44336"
android:textSize="22sp"/>
<TextView
android:id="#+id/gift_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#FFFFFF"
android:textSize="20sp"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
view.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
//Dismiss the dialog
}
return false;
}
});
view.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View view) {
//Create the dialog
return true;
}
});
Use setOnLongClickListener for creating the dialog and use setOnTouchListener for dismissing the dialog.
So you should add setOnTouchListener to the view. Call dialog.dismiss() when MotionEvent action is MotionEvent.ACTION_UP (user lifts his finger).
If the view is inside a scroll view the views onTouchListener does not get called. A simple solution is to add an onTouchListener to the scroll view and dismiss the dialog when user lifts his finger.
scrollView.setOnTouchListener( new View.OnTouchListener(){
#Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
//Dismiss the dialog
return true;
}
return false;
}
});
I have two views in my activity in my Android app. One View (we'll call this viewOne) has a bunch of SeekBars while the other view (we'll call this viewTwo) contains a Drawable that is redrawn whenever a user touches it.
viewTwo has an OnTouchListener. The issue is that when I touch viewOne to move a SeekBar, viewTwo's touch listener is getting called and this creates a huge amount of lag due to it needing to redraw every time the listener is called.
Why is this happening and how can I stop it? Thanks!
EDIT:
Main Activity Layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:orientation="vertical">
<com.rfoo.viewOne
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:id="#+id/vOne"/>
<com.rfoo.viewTwo
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:id="#+id/vTwo"/>
</LinearLayout>
View One Layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:orientation="vertical">
<SeekBar
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:id="#+id/sb1"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:id="#+id/sb2"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:id="#+id/sb3"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:id="#+id/sb4"/>
</LinearLayout>
View Two Layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/myView"/>
</LinearLayout>
Main Activity Code:
public class MainActivity extends AppCompatActivity implements View.OnTouchListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
// Initializations here...
// And then:
View viewTwo = (View)findViewById(R.id.vTwo);
viewTwo.setOnTouchListener(this);
}
#Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.vTwo) {
vTwo.invalidate();
}
}
}
You implemented View.OnTouchListener but you haven't used it. I think your purpose is using that to trigger onTouch()
public class MainActivity extends AppCompatActivity implements View.OnTouchListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
// Initializations here...
// And then:
View viewTwo = (View)findViewById(R.id.vTwo);
viewTwo.setOnTouchListener(this);
}
#Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.vTwo) { // you can use viewTwo instead of v as well
viewTwo.invalidate();
}
}
}
Well i am almost sure the problem is because the unused nested layouts i tried this and worked fine for me :
public class exampleActivity extends AppCompatActivity {
private static final String DEBUG_TAG = "Motion event";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.example_layout);
findViewById(R.id.myView).setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
return (v.getId() == R.id.myView) &&
handleGesture(MotionEventCompat.getActionMasked(event));
}
});
}
private boolean handleGesture(int action) {
switch(action) {
case (MotionEvent.ACTION_DOWN) :
Log.d(DEBUG_TAG, "Action was DOWN");
return true;
case (MotionEvent.ACTION_MOVE) :
Log.d(DEBUG_TAG,"Action was MOVE");
return true;
case (MotionEvent.ACTION_UP) :
Log.d(DEBUG_TAG,"Action was UP");
return true;
case (MotionEvent.ACTION_CANCEL) :
Log.d(DEBUG_TAG,"Action was CANCEL");
return true;
case (MotionEvent.ACTION_OUTSIDE) :
Log.d(DEBUG_TAG,"Movement occurred outside bounds " +
"of current screen element");
return true;
default :
return false;
}
}
}
And this is my xml layout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SeekBar
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".25"
android:id="#+id/sb1"/>
<SeekBar
android:layout_width="match_parent"
android:layout_weight=".25"
android:layout_height="0dp"
android:id="#+id/sb2"/>
<SeekBar
android:layout_width="match_parent"
android:layout_weight=".25"
android:layout_height="0dp"
android:id="#+id/sb3"/>
<SeekBar
android:layout_width="match_parent"
android:layout_weight=".25"
android:layout_height="0dp"
android:id="#+id/sb4"/>
<View
android:layout_weight="1"
android:background="#color/appframe__colorAccent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="#+id/myView"/>
</LinearLayout>
I have a scrollview inside which there is a editext which is multiline. I want to scroll the edittext to see the lower content but it can't be done.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#android:color/holo_blue_light"
android:gravity="center" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View Complaint"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="20dp" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Order Number 0100C1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Name of ClientClient 1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Subject : Measurement Issues"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:text="Description"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Lorem ipsum dolor sit amet, sapien etiam, nunc amet dolor ac odio mauris justo. Luctus arcu, urna praesent at id quisque ac. Arcu massa vestibulum malesuada, integer vivamus el/ eu "
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="Assign to"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:entries="#array/array_name" />
</LinearLayout>
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="15dp"
android:background="#eeeeee"
android:inputType="textMultiLine"
android:singleLine="false"
android:text="Android applications normally run entirely on a single thread by default the “UI thread” or the “main thread”.
android:textAppearance="?android:attr/textAppearanceMedium" ></EditText>
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Comment History"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="147dp"
android:src="#drawable/adddd" />
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Close Complaints"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/login"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_below="#+id/ll"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="15dp"
android:background="#drawable/login_btn"
android:text="Submit"
android:textColor="#android:color/holo_blue_dark"
android:textSize="25dp"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Can you guys help me in that . I think editText is getting the focus when cursor is inside it.
Thanks..!!!!!
Try this..
Add below lines into your EditText
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
Example
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="15dp"
android:background="#eeeeee"
android:inputType="textMultiLine"
android:singleLine="false"
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:text="Android applications normally run entirely on a single thread by default the “UI thread” or the “main thread”.
android:textAppearance="?android:attr/textAppearanceMedium" >
</EditText>
EDIT
Programmatically
youredittext.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (youredittext.hasFocus()) {
v.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_SCROLL:
v.getParent().requestDisallowInterceptTouchEvent(false);
return true;
}
}
return false;
}
});
First add this at XML
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:overScrollMode="always"
Then add the same above "OnTouch" but make it return "false" not "true"
public boolean onTouch(View view, MotionEvent event) {
if (view.getId() == R.id.DwEdit) {
view.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction()&MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_UP:
view.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
}
return false;
}
Kotlin version
Add the following lines to the EditText in your xml:
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
Add this to the Activity/Fragment:
myEditText.setOnTouchListener { view, event ->
view.parent.requestDisallowInterceptTouchEvent(true)
if ((event.action and MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
view.parent.requestDisallowInterceptTouchEvent(false)
}
return#setOnTouchListener false
}
Use this code it's working
In XML
android:singleLine="false"
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
In programming
edittext.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View view, MotionEvent event) {
if (view.getId() == R.id.edittext) {
view.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP:
view.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
}
return false;
}
});
you should use NestedScrollView class. This class support child scrolling inside parent scrolling. This class can be a child or a parent.
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#d6d8d9">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="512"
android:text=" your content"/>
<android.support.v4.widget.NestedScrollView
android:layout_below="#id/ll_button"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#d6d8d9">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="your content"
android:maxLines="512"/>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Building upon the answer by #Ayman Mahgoub and #Hariharan. The solution worked great except while scrolling the edit text there is no scroll momentum. As soon as the finger lifts up, the scrolling immediately stops.
To gain scroll momentum wrap a scrollview around the EditText and let the EditText's height wrap content (set minHeight if you'd like). Remove the following lines from the edit text:
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:overScrollMode="always"
Now the nested ScrollView wrapped around the EditText takes care of the scrolling. Update the onTouch handler to take into account the updated view hierarchy:
public boolean onTouch(View view, MotionEvent event) {
v.getParent().getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_UP:
v.getParent().getParent().requestDisallowInterceptTouchEvent(false);
break;
}
return false;
Be warned, this solution is now tightly coupled to the view hierarchy.
Gist: https://gist.github.com/atoennis/7549fba2634d0abccddf
I would vote up the updated answer provided by #Ayman Mahgoub, but I do not have a high enough reputation. His code works. I had to change return true to return false. You put the .setOnTouchListener() method in your java class and put the three lines:
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:overScrollMode="always"
in the corresponding xml file. You can see the implementation in the android emulator, and on the android phone you use for testing. Thank you so much #Ayman Mahgoub and #Hariharan!
This will scroll the EditText and make it editable:
First in the XML file, add this:
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
Then in the Java file, add this:
EditText.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
view.getParent().requestDisallowInterceptTouchEvent(true);
switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_SCROLL:
view.getParent().requestDisallowInterceptTouchEvent(false);
return true;
case MotionEvent.ACTION_BUTTON_PRESS:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(EditText, InputMethodManager.SHOW_IMPLICIT);
}
return false;
}
});
The simplest way is by doing Extention in Kotlin:
First add this extension:
fun EditText.enableScrollText()
{
overScrollMode = View.OVER_SCROLL_ALWAYS
scrollBarStyle = View.SCROLLBARS_INSIDE_INSET
isVerticalScrollBarEnabled = true
setOnTouchListener { view, event ->
if (view is EditText) {
if(!view.text.isNullOrEmpty()) {
view.parent.requestDisallowInterceptTouchEvent(true)
when (event.action and MotionEvent.ACTION_MASK) {
MotionEvent.ACTION_UP -> view.parent.requestDisallowInterceptTouchEvent(false)
}
}
}
false
}
}
and finally easily call this for your edittext:
editText.enableScrollText();
This extention works well in any case like inside ScrollView or RecyclerView or BottomSheet
Below Answer will help you to make Edit Text scrollable inside Scroll View and also show Count of it.
1.Make one rectangle_with_border_gray.xml file in #drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="0dp"/>
<solid android:color="#FFFFFF"/>
<stroke android:color="#7f848686"
android:width="0.01dp"/>
</shape>
2.Then, In #layout write below code in scroll view.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none">
<RelativeLayout
android:id="#+id/sv_profile_creation_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<LinearLayout
android:id="#+id/LL_optional_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_optional_message_title"
android:background="#drawable/rectangle_with_border_gray"
android:orientation="horizontal"
android:padding="#dimen/margin_02_dp">
<EditText
android:id="#+id/et_optional_message"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#color/colorWhite"
android:gravity="start"
android:hint="#string/why_not_leave_a_message"
android:inputType="textMultiLine"
android:isScrollContainer="true"
android:maxLines="5"
android:overScrollMode="always"
android:padding="8dp"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:textColor="#color/colorEditTextHintNormal"
android:textColorHint="#color/colorEditTextHint"
android:textSize="#dimen/margin_14_dp" />
</LinearLayout>
<TextView
android:id="#+id/tv_description_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/LL_optional_message"
android:layout_centerVertical="true"
android:layout_marginBottom="#dimen/margin_16_dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:text="0/200"
android:textColor="#color/colorLittleDarkGray"
android:textSize="#dimen/margin_12_dp"
android:textStyle="normal" />
</RelativeLayout>
</ScrollView>
3.Then, Inside your Activity or Fragment write below code:
TextView tv_description_count = (TextView) view.findViewById(R.id.tv_description_count);
EditText et_optional_message = (EditText) findViewById(R.id.et_optional_message);
private void makeScrollable(){
et_optional_message.addTextChangedListener(mTextEditorWatcher);
et_optional_message.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
view.getParent().requestDisallowInterceptTouchEvent(true);
switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_SCROLL:
view.getParent().requestDisallowInterceptTouchEvent(false);
return true;
case MotionEvent.ACTION_BUTTON_PRESS:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(et_optional_message, InputMethodManager.SHOW_IMPLICIT);
}
return false;
}
});
}
private final TextWatcher mTextEditorWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
//This sets a textview to the current length
tv_description_count.setText(String.valueOf(s.length()));
}
public void afterTextChanged(Editable s) {
}
};
Happy Coding......
First create a custom Scrollview class as given below:
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ScrollView;
public class MyCustomScrollview extends ScrollView {
public VerticalScrollview(Context context) {
super(context);
}
public VerticalScrollview(Context context, AttributeSet attrs) {
super(context, attrs);
}
public VerticalScrollview(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
switch (action)
{
case MotionEvent.ACTION_DOWN:
Log.i("VerticalScrollview", "onInterceptTouchEvent: DOWN super false" );
super.onTouchEvent(ev);
break;
case MotionEvent.ACTION_MOVE:
return false; // redirect MotionEvents to ourself
case MotionEvent.ACTION_CANCEL:
Log.i("VerticalScrollview", "onInterceptTouchEvent: CANCEL super false" );
super.onTouchEvent(ev);
break;
case MotionEvent.ACTION_UP:
Log.i("VerticalScrollview", "onInterceptTouchEvent: UP super false" );
return false;
default: Log.i("VerticalScrollview", "onInterceptTouchEvent: " + action ); break;
}
return false;
}
#Override
public boolean onTouchEvent(MotionEvent ev) {
super.onTouchEvent(ev);
Log.i("VerticalScrollview", "onTouchEvent. action: " + ev.getAction() );
return true;
}
}
Now in the activity or fragment where you are using the EditText, write the following code for the EditText object that you want to scroll inside the Scrollview :
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
EditText et;
VerticalScrollview sv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
private void init() {
sv = findViewById(R.id.sv);
et = findViewById(R.id.et);
et.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.sv) {
v.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
}
return false;
}
});
}
}
3.The follwing xml is given below:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<com.example.ayan.scrollableedittext.VerticalScrollview
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/sv">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="600dp"
android:gravity="center">
<EditText
android:id="#+id/et"
android:layout_width="200dp"
android:layout_height="80dp"
android:nestedScrollingEnabled="true"
android:gravity="start" />
</LinearLayout>
</LinearLayout>
</com.example.ayan.scrollableedittext.VerticalScrollview>
</LinearLayout>
Thanks to Hariharan, vovahost I got the same solution, but added performClick() to avoid a warning.
EditText (XML):
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
Code:
edit_text.setOnTouchListener { view, event ->
view.parent.requestDisallowInterceptTouchEvent(true)
if ((event.action and MotionEvent.ACTION_MASK) == MotionEvent.ACTION_SCROLL) {
view.parent.requestDisallowInterceptTouchEvent(false)
} else {
performClick()
}
return#setOnTouchListener false
}
Add this method in main activity:
It worked for me in Fragment
#Override
public boolean dispatchTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
View v = getCurrentFocus();
if (v instanceof EditText) {
Rect outRect = new Rect();
v.getGlobalVisibleRect(outRect);
if (!outRect.contains((int) event.getRawX(), (int) event.getRawY())) {
v.clearFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
}
return super.dispatchTouchEvent(event);
}
I have 3 XML files. The first one is for main activity. It has one button. When I touch this button, it works and it sends me to second XML file. Also the second screen has a button. Now, I want to make same operation here and I wanna go third XML file. But it doesn't work.
I did same procedure for all buttons. I can't find that where is my fault.
MainPageActivity:
public class MainPageActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_page);
ImageButton b1 = (ImageButton) findViewById(R.id.button_compare);
ImageButton b2 = (ImageButton) findViewById(R.id.button_find);
b1.setOnTouchListener(new View.OnTouchListener(){
#Override
public boolean onTouch(View comparePage, MotionEvent event) {
setContentView(R.layout.compare_pagee);
return true;
}
});
b2.setOnTouchListener(new View.OnTouchListener(){
#Override
public boolean onTouch(View findPage, MotionEvent event) {
setContentView(R.layout.find_page);
return true;
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main_page, menu);
return true;
}
}
activity_main_page.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainPageActivity"
android:id="#+id/mainActivity" >
<ImageButton
android:id="#+id/button_compare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="false"
android:adjustViewBounds="true"
android:scaleType="center"
android:src="#drawable/compare"
/>
<ImageButton
android:id="#+id/button_find"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="69dp"
android:adjustViewBounds="true"
android:src="#drawable/find"
/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center_vertical|center_horizontal"
android:text="Tap the top to Compare!"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/button_compare"
android:gravity="center_vertical|center_horizontal"
android:text="Tap the bottom to Find!"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
Compare:
public class Compare extends Activity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.compare_pagee);
ImageButton b3 = (ImageButton) findViewById(R.id.compareButton);
b3.setOnTouchListener(new View.OnTouchListener(){
#Override
public boolean onTouch(View comparePage, MotionEvent event) {
setContentView(R.layout.compare_pagee);
return true;
}
});
}
}
compare_pagee.xml:
<?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="match_parent"
android:background="#drawable/backgroundwallpaper"
android:clickable="true"
android:orientation="vertical"
tools:context=".Compare" >
<Spinner
android:id="#+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Spinner
android:id="#+id/spinner3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Spinner
android:id="#+id/spinner5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<ImageButton
android:id="#+id/compareButton"
android:layout_width="139dp"
android:layout_height="74dp"
android:src="#drawable/comparebutton" />
<Spinner
android:id="#+id/spinner6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Spinner
android:id="#+id/spinner4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
You're not starting new Activities, you're merely switching layouts in the first Activity. So the first button will work because it has a listener assigned to it in MainActivity. However b3 is is another Activity which never gets started, so depending on what you want to do, you can either start a new Activity for each button click, or you can move b3's Listener inside MainActivity.
First method (new Activities)
ImageButton b1 = (ImageButton) findViewById(R.id.button_compare);
ImageButton b2 = (ImageButton) findViewById(R.id.button_find);
b1.setOnTouchListener(new View.OnTouchListener(){
#Override
public boolean onTouch(View comparePage, MotionEvent event) {
startIntent (new Intent (MainPageActivity.this, Compare.class));
return true;
}
});
b2.setOnTouchListener(new View.OnTouchListener(){
#Override
public boolean onTouch(View findPage, MotionEvent event) {
startIntent (new Intent (MainPageActivity.this, Find.class));//You will NEED to make a new Activity called Find.
return true;
}
});
The second way (resetting content views in the same activity). I do not recommend it, since it makes things messy and goes against what an Activity should be, but it's still a (bad) option.
ImageButton b1 = (ImageButton) findViewById(R.id.button_compare);
ImageButton b2 = (ImageButton) findViewById(R.id.button_find);
b1.setOnTouchListener(new View.OnTouchListener(){
#Override
public boolean onTouch(View comparePage, MotionEvent event) {
setContentView(R.layout.compare_pagee);
ImageButton b3 = (ImageButton) findViewById(R.id.compareButton);
b3.setOnTouchListener(new View.OnTouchListener(){
#Override
public boolean onTouch(View comparePage, MotionEvent event) {
setContentView(R.layout.compare_pagee);
return true;
}
});
return true;
}
});
b2.setOnTouchListener(new View.OnTouchListener(){
#Override
public boolean onTouch(View findPage, MotionEvent event) {
setContentView(R.layout.find_page);
return true;
}
});
}
As you can see, b3's Listener extremely redundant - it doesn't do anything useful.
I suggest rethinking what you want your code to do, and rewriting it properly, since this is not proper structure.
I have a LinearLayout and I want to see when a user has touched it, and has released their finger. I thought I could do this by adding a onTouch listener and checking the event. This linearLayout holds a bunch of buttons.
My problem isn't the listener not working, it just isn't doing what I thought it would do. The listener only gets activated if ONLY the layout has been touched, which makes sense, but isn't what I want. If the user touches a button inside of the layout the layout listener isn't called, and I want it to be called.
Here is my code:
java code:
ll = (LinearLayout)findViewById(R.id.CategorySelect_lLayout_noID);
ll.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
Toast.makeText(CategorySelect.this, "action DOWN called", Toast.LENGTH_SHORT).show();
return true;
}
if(event.getAction() == MotionEvent.ACTION_UP){
Toast.makeText(CategorySelect.this, "action Up called", Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
my xml:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="400dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp"
android:scrollbars="none"
>
<LinearLayout
android:id="#+id/CategorySelect_lLayout_noID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<Button
android:id="#+id/CategorySelect_b_1"
style="#style/CustomBLUEButtonTextStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/CategorySelect_b_1"
/>
<Button
android:id="#+id/CategorySelect_b_2"
style="#style/CustomBLUEButtonTextStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/CategorySelect_b_2" />
<Button
android:id="#+id/CategorySelect_b_3"
style="#style/CustomBLUEButtonTextStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/CategorySelect_b_3" />
<Button
android:id="#+id/CategorySelect_b_4"
style="#style/CustomBLUEButtonTextStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/CategorySelect_b_4" />
<Button
android:id="#+id/CategorySelect_b_5"
style="#style/CustomBLUEButtonTextStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/CategorySelect_b_5" />
<Button
android:id="#+id/CategorySelect_b_6"
style="#style/CustomBLUEButtonTextStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/CategorySelect_b_6" />
<Button
android:id="#+id/CategorySelect_b_7"
style="#style/CustomBLUEButtonTextStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/CategorySelect_b_7" />
</LinearLayout>
</ScrollView>
Thanks for reading.
UPDATED CODE FOR COMMENTS:
My main xml file that is inflated from my activity:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/categoryselect_background"
android:scaleType="fitXY"
>
<TextView
android:id="#+id/CategorySelect_tv_chooseacat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="70dp"
android:gravity="center"
android:text="#string/CategorySelect_tv_chooseacat"
android:textColor="#FF5500"
android:textSize="34dp"
android:textStyle="bold"
/>
<Button
android:id="#+id/CategorySelect_b_settings"
android:background="#drawable/menu_settings"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
/>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="400dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp"
android:scrollbars="none"
>
<com.tdubstudios.soundboard.hungergames.ScrollAbleLinearLayout
android:id="#+id/CategorySelect_lLayout_noID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<Button
android:id="#+id/CategorySelect_b_cato"
style="#style/CustomBLUEButtonTextStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/CategorySelect_b_1"
/>
<Button
android:id="#+id/CategorySelect_b_cinna"
style="#style/CustomBLUEButtonTextStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/CategorySelect_b_2" />
<Button
android:id="#+id/CategorySelect_b_effie"
style="#style/CustomBLUEButtonTextStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/CategorySelect_b_3" />
<Button
android:id="#+id/CategorySelect_b_gale"
style="#style/CustomBLUEButtonTextStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/CategorySelect_b_4" />
<Button
android:id="#+id/CategorySelect_b_haymitch"
style="#style/CustomBLUEButtonTextStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/CategorySelect_b_5" />
<Button
android:id="#+id/CategorySelect_b_katniss"
style="#style/CustomBLUEButtonTextStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/CategorySelect_b_6" />
<Button
android:id="#+id/CategorySelect_b_peeta"
style="#style/CustomBLUEButtonTextStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/CategorySelect_b_7" />
</com.tdubstudios.soundboard.hungergames.ScrollAbleLinearLayout>
</ScrollView>
</RelativeLayout>
This is the ScrollAbleLinearLayout class:
package com.tdubstudios.soundboard.hungergames;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.LinearLayout;
public class ScrollAbleLinearLayout extends LinearLayout {
public ScrollAbleLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
public boolean onInterceptTouchEvent(MotionEvent event) {
requestDisallowInterceptTouchEvent(true); // Tell parents not to use this event
return false; // Tell children not to use this event
}
}
Yes I know the naming on some things have changed from my previous code, that is because I changed it to hide what type of app I was making (from search results). However for whatever reason I no long care, so that's the reasoning behind that.
Thanks.
THIRD EDIT:
So I'm currently using
#Override
public boolean onInterceptTouchEvent(MotionEvent event) {
//requestDisallowInterceptTouchEvent(true); // Tell parents not to use this event
if(event.getAction() == MotionEvent.ACTION_DOWN){
return false;
}
if(event.getAction() == MotionEvent.ACTION_UP){
return false;
}
return true; // Tell children not to use this event
}
And it works the way I want it to, however it isn't practical. For it to actually register the button clicks you have to make sure you don't move your finger at all left/right/up/down. It has to be like exactly down and exactly up. I was trying to add a onFling method, and then tracking the distance the finger as moved. And if it has moved less then x amount of pixels then make the main method return false which will allow the buttons to work, but if it was actually a swipe/move then the button doesn't need to get activated. Here is what I mean:
#Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (Math.abs(e1.getY() - e2.getY()) > MORE_THAN_X_INT) {
booleanVar = false;
return false;
}else{
booleanVar = true;
}
return false;
}
Then doing:
Override
public boolean onInterceptTouchEvent(MotionEvent event) {
//requestDisallowInterceptTouchEvent(true); // Tell parents not to use this event
if(event.getAction() == MotionEvent.ACTION_DOWN){
return false;
}
if(event.getAction() == MotionEvent.ACTION_UP){
return false;
}
return booleanVar; // Tell children not to use this event
}
I think that would work, but I can't test it because there isn't a onFling method for extends LinearLayout
Any suggestions?
Please note my returning true/false might be backwards, I'm not sure it's kind of confusing me. But if someone could lead me in a way to making that onFling method I can mess around with it to get it the correct values.
I have
#Override
public boolean onInterceptTouchEvent(MotionEvent event) {
//requestDisallowInterceptTouchEvent(true); // Tell parents not to use this event
while(event.getAction() == MotionEvent.ACTION_DOWN){
return true;
}
while(event.getAction() == MotionEvent.ACTION_UP){
return true;
}
return false; // Tell children not to use this event
}
and my buttons are never click able. But the ontouch listener works perfectly haha :|
I would recommend extending LinearLayout and using onInterceptTouchEvent to catch the touch event, then return true to force its children to not receive the events.
Something like this:
public class MyLinearLayout extends LinearLayout {
public MyLinearLayout(Context context) {
super(context);
}
public MyLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyLinearLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
#Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return true; // Tell children not to use this event
}
}
And, then in your XML, change LinearLayout to com.yourpackagename.MyLinearLayout.
Addendum: If you want both the Buttons and the LinearLayout to receive the event, you can change the onInterceptTouchEvent to this:
#Override
public boolean onInterceptTouchEvent(MotionEvent event) {
// Whatever touch event code you want, using the "event" variable
return false; // Allow children to use the event
}
So I never really found the answer to my question, but I found a way that works. Instead of putting a listener on the layout, I am just adding the onTouchEvent method for the full activity rather than a specific view.
#Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
Toast.makeText(CategorySelect.this, "action DOWN called", Toast.LENGTH_SHORT).show();
}
if(event.getAction() == MotionEvent.ACTION_UP){
Toast.makeText(CategorySelect.this, "action Up called", Toast.LENGTH_SHORT).show();
}
return super.onTouchEvent(event);
}
It doesn't effect any of the buttons, so it's exactly what I wanted. Thank you so much Soxxeh for working with me.