I'm working on an app and I want to add a view to the current view in a specific location if he checks a CheckBox but every time I try to add parent.addView(child) it crashes .. so I want to know how can I do this and how to release the view when the user clicks the CheckBox again.
That's a demo of what I want to make
https://xd.adobe.com/view/46d4808d-9888-455b-42ca-9fab587eb55d-30e5/
you can set the visibility in the xml file to gone and then set it back to visible when you click on the check box
xml:
android:visibility="gone"
jav:
view.setVisibility(View.VISIBLE)
You can create a Custom Component with the hidden content and reuse it in each checkbox. In addition, you can use a RecyclerView to add the checkbox. Or you can even create the custom component with the checkbox and hidden content and put all the logic there.
Related
Is there a way to disable clicks on views behind the ShowcaseView (inside the TargetView)? I have a very short tutorial and don't want users to be able to click through to elements behind the ShowcaseView because this interrupts its flow. Is there any way to disable clicking inside the TargetViews supplied to the ShowcaseView?
Create a view temporarily under the ShowcaseView but above anything you don't want clicked. Then call view.setClickable(false) this should prevent clicks from affecting that view or anything under it.
When you are done your showcase, just delete the extra view from the hierarchy.
https://developer.android.com/reference/android/view/View.html#setClickable(boolean)
I want to implement a row for a listview with two click zones with some special requirements:
What I want to implement is something like:
With the following click config:
The red zone links the user profile
The blue zone links the item detail
Clicks over the yellow zone are ignored
When clicking the blue zone all the row is selected (like with a background=?attr/selectableItemBackground)
I have tried several configs but I do not get all the points:
Config A: Add a clicklistener over the blue container and another over the red container, works nice but the full row selected effect when clicking the blue zone is missing.
Config B: Add a clickListener over the full row and another clicklistener over the red container, also works but the clicks over the yellow zone are not ignored.
How can I accomplish that?
Note: Also tried to use the Config B with an empty click listener over the yellow container. But sounds weird to add a clickListener to ignore it, and my real view is more complex than that and I should add a lot of empty clicklisteners. The ideal behavior should be the blue container to propagate its click status to the rowView
You can go with either A or B just with minor addition
A :
Call listview method void setItemsCanFocus(false) so when you click on Blue part, whole row will get focus
B :
Override isEnabled() method in your custom or base adapter and return false for the Yellow part. This will block click events to Yellow part
I hope your error will fix.
Thanks
So A works but you want to get rid the on pressed color ? If so add this in your ListView XML.
<ListView
android:cacheColorHint="#00000000"
android:listSelector="#android:color/transparent"
/>
You should have to implement a layout with Two Sub Layout in which One Contains the Avatar and another contains your data , while in Your Adapter Class You should have to add the tag with Specific Layout id and also add the OnClickListener for that Layout and then while You click the Layout You got the Tag and based on that Tag You are able to handle Your view in ListView Item.
I am getting text data from database. I am using Textview to show data
![Textview with scrollView]
I want two button at the bottom of activity (next) & (previous) which show data from database in pages style.
--> user click on next button
it shows scrolls data in that activity like pages
Basically i want to remove Scrolling and add pages turn feature in activity ![buttons used][1]
If i understood your question correctly you are trying to break incomming text into pages so that it fits your screen.
Firstly try to check Breaking large text into pages in android text switcher or view flipper
Instead of the viewflipper try using viewswitcher, which allows you to switch views after calling `getNextView() method. You only need to call this method with the "Next" button.
Hope this helps you ...
You can use ViewPager for this purpose, sample tutorial for ViewPager. First create a list containing you database values and then pass the list as parameter to adapter. You can also add next and previous buttons and use setCurrentItem method to navigate to next and previous accordingly. Hope it helps!!!
When I place a CheckBox in the row layout for a ListView, I am no longer able to recieve OnItemClick and OnItemLongClick events. On the other hand, using CheckedTextView allows these events to go through, but I don't know how to automate clicking on them in my JUnit/Robotium tests. Does anyone have any suggestions about what I can do to get the best of both worlds here?
You can make OnItem(Long)Click work if you set up the CheckBox views to non-focusable (i.e. setFocusable(false) and setFocusableInTouchMode(false), or their xml equivalents).
Note: The listeners will fire as long as you tap outside the checkbox itself. Tapping on the checkbox will toggle it only (but I guess this is what you would want).
I have a listView, where each row has a button in the row layout. However, this seems to make the row itself unclickable. How can I make both the button and row clickable?
Thanks.
You need to set itemsCanFocus on the list like this:
mList.setItemsCanFocus(true);
To make the button clickable. Then you will need to use your own adapter and in getView return a view which is Clickable and focusable. You will also lose the default highlight states so you need to put them back in with the background resource. So do this:
view.setClickable(true);
view.setFocusable(true);
view.setBackgroundResource(android.R.drawable.menuitem_background);
to your view before returning your view.
Whenever I see posts concerning the android:focusable and android:clickable attributes, I always see them being both set to the same value at once. I figured there must be a reason if they are two separate attributes instead of being one.
It turns out that a much better way of achieving your desired behavior is to set
android:focusable="false"
or
yourButton.setFocusable(false)
on the Button in your View. Once you do that, you'll be both able to set an OnClickListener on the Button, and a click on the row will fire the onListItemClick() method in your OnItemClickListener.
Try to set your widgets to non clickable and non focusable in xml,the click on items will work normally and also the click on button will work normally.
android:clickable="false"
android:focusable="false"
Hope this helps.
Unfortunately I don't think that is possible. You ListView row can either have focusable widgets, like a button, or be clickable, not both. See link.