Android: Detect if user touches a view inside parent view - android

I have 40 ImageViews inside a GridLayout, they have different colors and I want to know if user touched the desirable image or somewhere else(for example if user touched red image). How should I do that?

Set an OnClickListener for each view and store the views. In onClick you can check the view and know what ImageView was clicked. You could also think about changing the type to ImageButtons!
If you have further problems with your Grid not being able to be clicked, check this out: http://cyrilmottier.com/2011/11/23/listview-tips-tricks-4-add-several-clickable-areas/
TLDR: Disable focusing of the views in your layout.

If you manage your images in a collection maybe think about switching to gridview and implement an adapter with an itemClickListener. So depend on which item is clicked do you action.
How GridLayout items come from the Adapter(List/Image) in Android App

Related

Swipe and tap to enlarge recycler view

I have a recycler view which has its items in a card view. The recycler view gets its data from a sql database within the app . Now I want to implement two features to this recycler view items. First , whenever the individual cards are tapped , I want them to enlarge and display more data and should shrink back when tapped again. It is not like the case of expandable list view where it expands into a child list view. I want the height of the card to increase and just show some more information and buttons. Second I want the items to swipe left . I know there is a feature for that in recycler view , but I want to customise the swipe feature. Swipe from right should be locked , and when swiped from left , It should not go off list completely. It should show two buttons and should go off list only when one of the buttons is clicked. I have been looking , but there is no proper explaination anywhere. Please guide me through this process.
For your first question, set the adapter layout_height to wrap_content and set the buttons visibility to GONE. Implement the OnClick listener in the RecyclerView adapter and set the visibility of the buttons to VISIBLE if GONE and GONE if VISIBLE or use a boolean to alternate the visibility.
For your second question, this might help:
https://www.learn2crack.com/2016/02/custom-swipe-recyclerview.html
How can I make my Android SwipeableCardViews more like the IOS 7 mail app (swipe to show buttons)
https://github.com/daimajia/AndroidSwipeLayout

How to display a group of images from drawable to let the user pick one (Android Studio)?

I currently have an activity with a horizontal scrollview, and inside it I have an add button (ImageView) to let the user add some images to the same horizontal scrollview after clicking it. How can I display a group of images from app resources (such as drawable) as a sort of "pop up" to let the user pick one, without changing the current activity?
You need to create recyclerView with horizontal layout. The adapter of the recyclerView will have the functionality to implement a button click. The onClick of the button will add items to the adapter. These items may contain your required images.On every button click you need to call notifyDataSetChanged.
This can be solved by inflating a custom xml layout (containing a GridView) on an AlertDialog. To display the images on the GridView you need to create and set a custom adapter to it. The adapter shall have a function getView(), which will return each of the Views to be shown on Grid cells. You can also use Picasso Library to load the images.
Here is a brief tutorial
http://www.101apps.co.za/articles/gridview-tutorial-using-the-picasso-library.html
Hint: Remember to define the number of columns of the grid, and calculate the size of each image based on the screen size. This way you can fit the amount you like on each row. You can do this for both portrait and landscape orientations by overriding the function onConfigurationChanged.
Hint 2: Remember a GridView already has the scroll property, which needs to be activated (android:scrollbars="horizontal"). Using a ScrollView as parent of a GridView will cause it to wrap the image, even with MATCH_PARENT property activated, causing layout problems.

GridView delete multiple items like iphone apps uninstallation View

I have a GridView in which I am showing list of books. I have tried by creating custom layout and putting cancel button onlongclick listener of a view. But i am not able to apply a shaking animation to the items. Can anyone guide me how can i apply an animation to the items and make it similarly like iphone?
Now I want to provide feature to delete the Multiple items from the GridView like the View which shows as below:
I did lots of research for this ,but failed to get such kind of view in Android.
Can any one guide me for this?
You'll have to make a custom gridview for that. Place a button (x) on top of the grid item and set its visibility to invisible.. onLongPress of the grid item, make that button visible.. onclick of the button, delete that grid item by getting its id.
Hope I have given you a direction.

Button in ListView malfunctioning

I have a button in each item of a ListView whose background is defined by an XML, one background when enabled and another when disabled. When the ListView loads, it comes out correct. But, for some reason I can't figure out, if I scroll down and then scroll back up, the wrong background shows up.
I'd like to know the solution to this problem, but besides that, in general what I want to accomplish is this:
I have a button in the ListView to take the user to the website for the given item. If there is no website, I want the button to disappear, or be disabled. I seem to have the same problem with both options.
Thanks in advance for your efforts
It seems most likely that the problem lies with your getView() method. Android recycles views to save memory, so, for example, when you scroll down, it calls getView(int, View, ViewGroup) on your adapter where View is the item that just left the top of the screen. If you're not re-populating the item with the new data from the adapter, (ie, just returning convertView) it will put the View that left the top of the screen where the "new" one should be.

android ListView child animation

I build a Listview, each item of this Listview in a layout composed of a Gallery.
On click of an item of the Gallery, I want to translate it to the top of my screen.
Even with setZAdjustment(Animation.ZORDER_TOP); my gallery cell doesn't move outside the gallery.
I assume it's because it can't go outside it's parent view.
Is there a way to do this ?
Thanks
I assume it's because it can't go outside it's parent view.
you are right.
There is no way that you can move that exact view. What you can do is make yourself a new ImageView and add it to your top level layout right over the top of the selected cell. Set its image by calling .getDrawingCache() on the gallery cell. Then you can animate your new ImageView to where ever you want.
Depending on what you want to do with it once it has been moved this might work out for you. But fair warning it is a somewhat convoluted process to achieve the effect you're after

Categories

Resources