iOS: TableView with expanding cells - android

I'm currently developing an iOS version of an Android app. On one screen I have a series of rows that, when clicked, expand to provide for information.
Before click:
After clicks:
How can I replicate this behavior in iOS? I don't know whether I should use a table view or just construct generic UIViews. I am using Auto Layout.

You can reload UITableVIewCell at particular NSIndexPath and calculate new height for cell.
Check:
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
from UITableView and
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
from UITableViewDelegate.

Simply customize your header views for each group in your UITableView. Use viewforheaderinsection method to do that, and return UIButton for example. And if you tap that button, you should insert UITableViewCells in this selected group. I cant give you a code because I'm on windows now, but it's very simple to do.
UPD: look at this sample code by Apple: http://developer.apple.com/library/ios/#samplecode/TableViewUpdates/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010139

When you receive the touch event for expanding your table cell, use the following calls in your table controller
[self.tableView beginUpdates];
[self.tableView endUpdates];
Though the animation block is empty, calling beginUpdates the endUpdates causes the table view to refresh cell layout and animate changes. This will cause your table view delegate to be re-queried - so ensure you implement the following method in your UITableViewDelegate (Usually you will have set this to be the UITableViewController):
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
Ensure this method will return the appropriate expanded cell size after the touch event is received. The result will be a nice smooth cell expansion animation :)

Related

Android detect tap or move - for chess piece interaction

I want to implement touch listener that detects
Click/tap on chess piece in order to select ot
Swipe/move of chess piece immediately.
How to do it?
Unfortunately, I am not sure what you mean by a "chess piece", but let's assume that the board is a view in the background, and inside you have inner views which are chess pieces.
To achieve the select/unselect given piece effect you should add a simple View.OnClickListener interface to your view. Each of your pieces should have a view class and some data connected to it (like a position, a type of piece, id, etc.). After clicking the piece update the state of some global variable, for example, selectedPiece with an ID assigned to a given piece. You should also change the UI of a given piece, for example change the border to show the selected piece to a user. Then after clicking a new field for moving the piece you should update the UI by moving your piece view to an appropriate position. Also, the data of a piece or a game should be updated - depending on the place of storing the pieces' positions.
For this you should implement the drag&drop feature which is described here: https://www.tutorialspoint.com/android/android_drag_and_drop.html. You should determine the places where the user can move a piece and in case of dropping the piece in the wrong place, cancel the move and go with the piece to a start position.
Basic response to touch events using event.x and event.y works:
https://developer.android.com/develop/ui/views/graphics/opengl/touch
https://suragch.medium.com/how-touch-events-are-delivered-in-android-eee3b607b038
...more info:
Android Touch Listener

Dynamically TreeLayout

I've been trying to create this logic for 2 days and even though on paper looks like a relatively simple problem, there are a lot of cases that mess this up while effectively writing the code.
After querying a web service, I receive this type of response:
I need to create a layout dynamically depending on the answer to simulate this behavior:
There is the main spinner that has all the root items. If I select one item there is 2 choices. If it doesn't have any children, I only add a textview. Otherwise I add a new spinner that has the children as options and if a children is selected, a new textview is created underneath. This goes recursively.
I successfully implemented this and it works only for 2 levels (the json presented without the id '5' element). I want this to work for an unlimited number of levels. The problem appears when i have a 3 level tree and i select on the middle node. I want to hide his edit text, but also the spinner and the edit text of his child and I don't have a direct access to the newly programmatically created views.
Use recursive function. Stop recursion if child's node is empty. So you make first call on first item, if it have no children go next, if it have children call this function again.
Deleting view depends on root element you've selected. If it is RecyclerView then just update collection and notify adapter/use DiffUtil callback.
If you adding view dynamically then just set View id on creation and remove view by id on updates.
Set id to dynamically created view using View.generateViewId() like urview.setId(View.generateViewId()) and as per your need, remove them using id.

Scrolling in GridViewPager on Android Wear

I am currently designing a wearable app that uses a GridViewPager with 4 rows and 5 columns.
I have several questions regarding the scrolling:
Is it possible with a Java function to go directly to a specific line and column? I tried scrollTo but it isn't working.
Is it possible when changing line to always go in the second column or to stay in the same one instead of always coming back to the first one?
Or is it possible to go to another layout when swiping from left to right when on the first column instead of dismissing the app but with the ability to dismiss the app from this new activity?
For part 2 of your question, you can override getCurrentColumnForRow(int row, int currentColumn) in a custom GridPagerAdapter and set it to return currentColumn. That will allow it to stay in the same column when changing rows.
Regarding part 1 of your question:
scrollTo is used to change a view's position on the screen.
You can call GridViewPager.setCurrentItem(row,col) instead.

Gesture Detection with more Items android

In my application, I save data in my sqlite db a variable number of notes composed of: (IDNote,title,body, date of creation, owner of note, icon_name). When i save and query the DB, my data are all ok, so my question is, Is possible to implement GestureDetection for moving and restore a single icon that correspond at a single note ? Because a found an example but all the icons are moved, but i want to move only one icon at time simulating all the gesture of the icons of Desktop computer.
Thanks in advance.
Marco
Set an OnTouchListener on the view that holds your icon. This listener is called when an ACTION_DOWN event on the view is caught.
Here register it somewhere as the 'currently dragged object'. Make sure onTouch() returns false, so the event is propagated further to your views parent.
This parent is responsible for checking whether a view has been registered as the 'currently dragged object'. Also, it has to call your Gesturedetector, which in onScroll will do the actual scrolling and moving.
This is just an idea, tell how it went!

Rows and Columns layout in Android Widget

Things are simple, I want to make a widget with 4 lines and 4 rows in it, on each cell there would be a click-able image and an action set by the user via the Settings page.
The layout is like this:
What layout element is recommended to be used for this scenario ? Should I use a GridView, TableLayout, more Linearlayouts ? Keep in mind that the spacing between items must be the same. I want to make it as light as possible. So, what layout ?
If I decide to use a GridView do you have any simple tutorial about
this? I can't manage to find a way of accessing the GridView from
AppWidgetProvider and set it's Adapter. Thank you.
LE: It seems that GridView is supported starting from Android 3.0.. please correct me if I'm wrong. In this case the only remaining thing to do is add 16 images and for each image add a onClickListener ? Brrr...
If you use a GridView then half of your work is done for you - The only layout and formatting elements you need to consider are on a Global (GridView) and Item level.
Using a GridView will also give your Scrolling functionality and the ability to change your row/columns count based on your device (4x4 on tablet, perhaps 2x8 on a phone).
Creating an extension of BaseAdapter to attach the Grid's children will also give you the flexibility to check items, multi select and will allow you to quickly modify the implementation in future by adding and removing items at will.
If this is simply a 4x4 grid which will always ALWAYS remain the same independent of device and each "Item" will always be the same, Use a RelativeLayout as it will be the most lightweight and efficient ViewGroup.

Categories

Resources