android View reset setNextFocusUpId to default behaviour - android

I'm implementing this to android tv box with remote functionality.
I have a LinearLayout in ScrollView containing generated View.
I'm programmatically set the NextFocusUpId for the first View to the last View and vice versa so when user navigate up through the first View, it's rotate to the last View and vice versa.
the problem is when i sort the list with alphabetical order later, the first and last View got place in the middle, and when user navigate up through the list and arrive at the first View (before the sort), it's jump to the last View (before the sort), instead of the View next up to it.
if I set the NextFocusUpId to itself, user cannot navigate through the View before and after the sort of the View.
view1.setNextFocusUpId(view1.getId());
if possible I'd like to avoid to manually iterate the views and add the NextFocusUpId and NextFocusDownId in each view when the sorting is being run.

When this question being made, I found this solution.
view1.setNextFocusUpId(View.NO_ID);
do the reset.
EDIT:
It appear that in the documentation, there is the solution in the documentation
http://developer.android.com/reference/android/view/View.html#setNextFocusDownId%28int%29
Parameters
nextFocusDownId The next focus ID, or NO_ID if the framework should decide automatically.

Related

Correct way to adapt behavior based on the device size in Xamarin.Forms?

I am coding a basic adaptive UI using Xamarin.Forms. I have one view with a list of items in it and if you tap one of the items, it opens up a second view which show the item details. When the app is running on a phone, I want it to show a new page with the item details while when I am on a tablet, I want for the details to be shown as another view next to the original view with the list of items. What is the correct way to do this?
So far, my idea was that I would call a method in the parent page, which would decide based on the device type whether it should open up a new page or add a view to a stack layout next to the original view. I've read though that it's not exactly clean to reference the parent page from a child viewmodel, since the page method would be called by a command from the child.

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.

Android: How to use fragments to completely change a view

My app has a custom segmented control(got it from internet - its really a radio group) and under it a listview. When a user clicks on a row in the list view, a fragment is attached to the activity that displays a different listview. This new listview seems to replace the old one. The problem is that the segmented control is still there, whereas I would like the whole view to be the new list view. Knowing that fragments are embedded in the view group, I thought progammatically removing the segmented control would work, but it didn't, the control just becomes empty space.
It's important that the app works the way I described. I could explain in detail why this is so, if needed.
Any tips? Much appreciated.

Infinite scroll in LinearLayout/ScrollView?

I know it's somehow possible to make a ListView that loads more data when the user has reached the bottom of the list. However, I'm working with a ScrollView, which I have a LinearLayout in, and these two components works great with the scrolling and so. But I don't know how I'm supposed to do so it gets an infinite scroll.
I suppose I need to add something that reads what is shown of the LinearLayout on the screen, and when it calculates that it is the bottom of the LinearLayout that is being shown (by using the current position and the height of the View), it triggers an event.
But as I said, I don't know how to accomplish this. So, if anyone can give me some help I would be very grateful.
EDIT: I found this post here on StackOverflow How to trigger an event when scrollView reach the bottom with Android?, but I don't know what to do with the answer:
Given the requirements, you'll likely be extending BaseAdapter (as opposed to CursorAdapter which utilizes a different mechanism).
Here's a snippet for that:
public View getView(int position, View convertView, ViewGroup parent) {
if (position == backingLinkedList.size()) {
//get more items and add them to the backingLinkedList in a background thread
notifyDataSetChanged();
}
}
If you can trigger an event when you reach the bottom of a scrollview, You could try creating your own type of view to hold your data. When you reach the bottom of the view load the next data into your view class and add it into the layout of the scroll view.
So basically create a class that holds a section of what your showing. Add the first one into the scrollview. When you hit the bottom create another view holding your next data and use scrollviews_layout.addview(view_holding_the_new_data)
I know this was solved a long time ago, but I wanted to share my solution for future infinite scrollers.
I used the onScroll method within the OnScrollListener to trigger a background thread to grab more data and adapter.notifyDataSetChanged to notify the ListView of more data to load and create an infinite scroll. For some reason, onScrollStateChanged wasn't triggering, but onScroll did what I needed so I didn't need to bother.
For the longest time I didn't understand how to keep the ListView from reloading and placing me back at the top of the list, but then I realized I only need to initialize a new adapter and call setListAdapter once, and every time after that, only call notifyDataSetChanged. Before, I was also calling setListAdapter, thereby placing me back at the top.

issue while place the radio buttons inside the liview in android?

I have a listview with radio button. when i click any option and scroll that list view the previous select will cleared.How to do this. The actual problem is when scroll the view on every scorll the view is refreshed, that's why every time the view is refreshed. How to do this I can't get any solution, Plz. Help.
Check your adapter, you are probably don't do the job right on bindView. You have to set again on bindView the values.
I will reformulate the sentence and you will probably will understand.
The newView creates only 5-10 views (as many they fit on the screen), and they are reused for other rows. If you have a ListView with 200 lines in it, actually you have only 5-10 views, and you have to make sure you update the views with the valid changes in bindView. You have to store/save the changes to an object for later reuse.

Categories

Resources