OnLongClick() blocks the other clicks on the parent view - android

I have a strange behavior, I use a RecyclerView to display a list.
Each item of this list is composed of a LinearLayout containing 2 TextViews. (It's a classic configuration).
I have an OnClickListener on the LinearLayout and an OnLongClickListener on the second TextView.
The problem is that the OnLongClickListener prevents the "normal clicks" to reach the LinearLayout.
To summarize:
If I click on the first TextView, the Layout is clicked.
If I click on the second TextView, nothing happens.

You can't avoid this situation with your current xml file, you may need to make adjustment
Though if you want it with this design, you have to add OnClickListener to your second text that have OnLongClickListener and call inside it whatever you call on linearView.OnClickListener .

When you clicked on TextView just disable all click of linear layout because at a time one click listener will work.
linearlayout.setClickable(false);
linearlayout.setEnabled(false);

Related

Display rest of layout fields on button click on same View

I have layout containing 30 fields ( using editbox, spinners, buttons etc)
but it looks too weird with crowded elements. ( scroll view is also longer)
So i decided to keep 1 more button, so firstly 15 fields will display and 1 "More" button below,now i want to display rest of fields onClick "more" button on same layout ( below that 15 fields). How to do this, thanks in advance
I would suggest you to make a parent view with two main relative layouts. First relative layout for all the content you want to show at first time. Make this layout visibility View.VISIBLE. Second relative layout for all the content you want to show on click event. Make this layout visibility View.INVISIBLE.
On button click event make second relative layout visible by setting view.setVisibility(View.VISIBLE)
Don't forget the invisible the layout in the end. Otherwise it will be visible throughout the app session.
You can also set this property in your xml too. There is a android:visibility="visible" tag in every view.
This approach will help you in management because by setting a single view visibility you can manage your all view. Happy Coding!!

Android: Let Parent View Handle On Click

I have a RelativeLayout that contains a few items: An ImageView and a few small TextView's.
Functionally I want to have the same on click event fire when anything in the RelativeLayout is clicked.
Visually I want to see the background of the RelativeLayout change so that it shows the entire layout (or "item") is being clicked.
My problem is that every time I click on the TextView's the on click doesn't propagate back to the parent view and so the background color doesn't change. How can I do this?
Ensuring you got no OnClickListener assigned to any of the childs of your RelativeLayout shall usually suffice for them to not receive clicks. Also check if you got no android:clickable="true" set by any chance for it. Then once you assing OnClickListener to your RelativeLayout it should get all the clicks.
for some items that has internal OnClickListener and you cannot easily remove their implementation of OnClickListener like SwitchComat, you can set
android:descendantFocusability="blocksDescendants"
on your parent layout. by adding this attribute to the parent view, non of the children will receive click events regardless of having onClickListener or not.
more on descendantFocusability

Android listview with buttons

I have a listview with custom listitem. I have bunch of textviews in Relative layout. And when I click on listitem it goes to different screen. Now I have added 3 buttons and toggle button to list item and I CAN NOT CLICK THE LIST ITEM. What am I missing :(
set focusable property of all the buttons to false and so that you can click on list and also touch event for all buttons will work
When the user clicks the row, the ListView will look for a widget implementing the Checkable interface. The RelativeLayout does not. An easy way to do that is simply to create your own CheckableRelativeLayout class. See http://www.marvinlabs.com/2010/10/custom-listview-ability-check-items/ for a full tutorial with code.
Also, the buttons and other items in your row layout should not be focusable. You can see other SO questions: Android Row becomes Unclickable with Button

Android, Layout clicklistener and subview click through problem

I have a RelativeLayout to which I add buttons and set their onCLickListener to the current Activity where I handle their clicks.
Under a particular circumstance I need to set the RelativeLayout onClickListener also, but then once finished with the required clicking on the layout, I need to allow clicking on the buttons again. (i.e. clicking throug hthe layout)
If I set the layout's click listener to null I can no longer click either the layout or the buttons that are it's child views.
What am I doing wrong?
EDIT: I seem to have fixed it by setting;
relativeLayout.setClickable(false);
Have you tried:
relativeLayout.setOnClickListener(null);
relativeLayout.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
?

how to scroll up when choose some item at item list in android?

I jave a list of item (linearlayout inside a scrollview where i add buttons vertically to linearlayout dynamically from the java code ) ? i need when i click on one button the item moves up (scroll up) , to make the item at the first of the screen ??!
Well I never did that, but from the ListView reference it seems pretty clear that set setSelectionFromTop is what you are searching for.
See also how-to-autoscroll-a-list-view-in-android

Categories

Resources