how to make recyclerview slide horizontal - android-recyclerview

i made a recycleview that works just fine and gets the data and show it but i want that instead of vertical scroll it will be horizontal scroll.
i searched and read that to control the scroll orientation behavior i need to use the LinearLayoutManager and set it like this:
LinearLayoutManager mLayoutManager = new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false);
recyleview.setLayoutManager(mLayoutManager);
but it dosent work and i dont know why all the examples i saw are with this at the core
anyone have any idea why?\
thanks for any help :)

it was about this line:
LinearLayoutManager mLayoutManager = new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false);
but since i tried a couple of tutorials i had this line somewhere else in my code that i forgot to delete it. the problem it was set with .VERTICAL so when it run the code with .HORIZONTAL was running just fine but because later in the adapter initialize i had the same line but with .VERTICAL so it just overwrite the .HORIZONTAL
so in conclusion just make sure you have ONE LinearLayoutManager initialize at a time :D

Related

Disable the back button in navigation bar

I need to get rid of only the arrow in the navigation bar in Xamarin forms. I tried in but I didn't get a proper solution. please help me overcome this issue. Thanks in advance.
!! I NEED TO REMOVE PERMANENTLY
solutions that I'm tried up to now :
Shell.SetBackButtonBehavior(this, new BackButtonBehavior
{
IsEnabled=false
});
but still, this didn't help me
There is a easy workaround to solve this.
You could override a Icon with a transparent png file(Follow is a transparent png):
and set enabled be false as follows:
Shell.SetBackButtonBehavior(this, new BackButtonBehavior
{
IconOverride = "transparent.png",
IsEnabled = false
}) ;
Then the effect as follows:
Note: You will see that we also can tap that area, therefore we need to set enabled be false.
Based on this official sample to test that.
You can set this using the Xamarin.Forms.NavigationPage class, from within a view's code behind file. E.g. within a ContentPage's constructor.
NavigationPage.SetHasBackButton(this, false);

Adding ToolBar to GridLayout

I have a Gridlayout, and I am adding Link objects to the gridlayout. The code for the same:
GridLayout gridLayout= new GridLayout(items.size(), false);
gridLayout.marginWidth= 0;
gridLayout.marginHeight= 0;
gridLayout.verticalSpacing= 0;
gridLayout.horizontalSpacing= 0;
fComposite.setLayout(gridLayout);
fComposite.update();
fComposite is a composite with Gridlayout. The output is something like:
Everything is good uptill here. Problem arises when I try to add a ToolBar to this composite. I am adding toolbar like this:
ToolBar toolBar = new ToolBar(fComposite, SWT.BORDER| SWT.VERTICAL);
ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH);
toolItem.setText("<<");
When I do this, output is like this. All the Line object shifts down and is half cut:
I guess the problem is that width of toolbar is more than of link object. When I make a new Shell and try to emulate the same thing it works fine. I guess the problem is in how the parent of this GridLayout is defined. It's a GridLayout. If it helps, I am working with trying to modify the BreadCrumb of JavaEditor of Eclipse IDE. Any help or lead will really help. Thanks.

Update RecyclerView adapter after SharedPrefereces changed

I have RecyclerView with custom RecyclerView adapter.
Each row of RecyclerView "opens"(when user clicked on it) using CardFlipAnimation(AnimatorSet).
In each row there is a button that change int value in SharedPreferences , and TextView that shows this value.
If i have opened more than one row i need dynamically change all TextViews in all rows which are opened.
NotifyDataSetChanged and etc updates data in RecyclerView great but the is a problem that they close opened rows(because for standart thay are closed and then open with AnimatorSet)
My main mission now is to understand how to update only one TextView in all opened rows and to keep them opened(dont touch AnimatorSet).
I think i can use an Observer,but i didn't know how correctly implement him.
If you any ideas please help me.
Thanks for answers
Ok, finaly i got a solution , it's a little bit ugly but it works exactly as I need.
First: I pass my RecyclerView to Adapter
...
public CardBaseAdapter(RecyclerView recyclerView,...) {
...
this.mRecyclerView = recyclerView;
....
Second: Create a method in my Adapter :
public void updateViews() {
for(int i =0;i<getItemCount();i++){
HeaderViewHolder holder = (HeaderViewHolder)recyclerView.findViewHolderForAdapterPosition(i);
if(holder!=null){
//Update views at holders
}
}
}
Third: Call this function when i need to update view
P.S. I'm not sure that this is the correct way to update view's , but it works, if you know another, good solution , post it pls

tvOS: Focus first button as preferred focus view when buttons are in horizontal order

I have been trying to focus the first button but focus engine takes the third button right below the tab bar as the first item to be focussed. I tried with preferred focus view but found that when i place the buttons in vertical order then preferred takes the preferred view to be focussed but when i placed all the buttons in horizontal plane it always takes the third button.The other approach i can think of if Focus Guide but i wonder how that will work in this scenario?
override weak var preferredFocusedView: UIView? {
get {
return thrirdButton
}
}
It happens because focus engine takes the nearest possible focus element as 1st element as you can see from the picture attached.I have attached the context screenshot for the view controller. Any help or clue to solve this will be appreciated.
Solution :
We need to add focus guide just above button 3 and redirect it to button one when the focus guide is focussed.
private var focusGuide = UIFocusGuide()
self.view.addLayoutGuide(focusGuide)
self.focusGuide.bottomAnchor.constraintEqualToAnchor(self.button3.topAnchor).active = true
self.focusGuide.leftAnchor.constraintEqualToAnchor(self.button3.leftAnchor).active = true
// Width and height
self.focusGuide.widthAnchor.constraintEqualToAnchor(self.button3.widthAnchor).active = true
self.focusGuide.heightAnchor.constraintEqualToAnchor(self.button3.heightAnchor).active = true
focusGuide.centerXAnchor.constraintEqualToAnchor(self.button3.centerXAnchor).active = true
override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
self.focusGuide.preferredFocusedView = button1
}
Try adding a UIFocusGuide just above the button rows. In that case, before reaching the button, it will hit your focus guide in which you can redirect the preferredFocusedView to that particular button. The code to redirect is to be done by overriding didUpdateFocusInContext method.
Assuming you have setup the focus guide in viewDidload, the following is a sample,
override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
super.didUpdateFocusInContext(context, withAnimationCoordinator: coordinator)
self.focusGuide.preferredFocusedView = self.mypreferredbutton
}
TO initialise a focus guide ( Do the addition of guide to view in viewDidLoad)
var focusGuide = UIFocusGuide()
self.view.addLayoutGuide(self.sidefocusGuide)
self.focusGuide.leftAnchor.constraintEqualToAnchor(self.placerLabel.leftAnchor).active = true
self.focusGuide.rightAnchor.constraintEqualToAnchor(self.placerLabel.rightAnchor).active = true
self.focusGuide.topAnchor.constraintEqualToAnchor(self.audioTable.topAnchor).active = true
I too faced a similar issue but somehow able to do it through this. The preferredFocusedView approach will also work, but you have to do lot of circus by updating some reference variable and then calling setneedsfocusupdate for that view. Try the focus guide way. Hope it helps.
EDITED:
I have added code how to setup the guide. In this case I have put the guide on the right side of my view. So, whenever your focus hits the guide, it redirects to the preferredfocusguide view that you want the focus to go to in the didUpdateFocusInContext. "There is only one view in focus at anytime.", remember thes ? So, the moment it hits the guide, the overriden method gets hit which in turn moves your focus to the guide's preferred view. For examples, you can refer to Apple's UIKitCatlog app for tvOS and here is one link explaining the same.
The best way to give the initial focus to your preferred view is by using preferredFocusEnivronments.
override var preferredFocusEnvironments: [UIFocusEnvironment] {
return [firstButton]
}
preferredFocusEnvironments will be called before didUpdateFocus, that way you can inform the system, where you want the focus to be redirected.

AppBarButton.Icon doesn't change on runtime

I have a problem updating AppBarButton Icon on runtime depending on some conditions.
<AppBarButton x:Name="WeekButton" Click="OnClick" Label="SomeText"
</AppBarButton>
I'm trying to update Icon property in some code behind with this code
WeekButton.Icon = new FontIcon() { Glyph = Runtime_Value_Here};
But nothing happens. The button doesn't change. But in any random time when the code works, It MAY change the button. I always see, that the Icon is new in code, but not on screen. None of the UpdateLayout helps.
Would appreciate any help.
Thanks
UPDATE:
It seems to not working with FontIcon, as with BitmapIcon changing everything works fine.
Force InvalidateArrange and it works
WeekButton.Icon = new FontIcon() { Glyph = "\uE29B", FontFamily = new FontFamily("Segoe UI Symbol")};
WeekButton.InvalidateArrange();
I believed you already found the solution with bitmap icon.
But some people who reached this page and want to know the solution like me,
Here is using bitmap icon and changing app-bar button icon dynamically.
BitmapIcon _bitmapIcon = new BitmapIcon();
_bitmapIcon.UriSource = new Uri("ms-appx:///Assets/yourBitmapIcon.png");
WeekButton.Icon = _bitmapIcon;
Try using the IconUri in order to give the value.
WeekButton.IconUri = new Uri("/Images/pause.png", UriKind.Relative);
Reference: Disable/Enable applicationbar Button in runtime with event textchanged (Windows Phone)