In Codenameone, I've used the list as container renderer to form and after parsing JSON data using hastable, I shown results on items of the list. The list contains hastable has been passed over ListModel and it works fine . Whenever I use ListModel , I just want to click on list item and action triggers. Problem is using ListModel it has only
datalist.addSelectionListener(new SelectionListener() {
public void selectionChanged(int oldSelected, int newSelected) {
// TODO Auto-generated method stub
}
});
I won't be able to scroll the whole page due to select on any item, it triggers the action.
Any option how I can scroll whole results on page as well onClick so that I can trigger the action?
Use action listener in the List not the list model.
Related
All of my property values require me to click them in order to see them. How can I fix this?
The object I'm trying to view is this Query Object. It seems to do this with most Arcgis objects I'm trying to view.
You can try putting it through JSON stringify which will call all the getters:
console.log(JSON.parse(JSON.stringify(myObj)));
The issue is, calling a getter can have side effects e.g.
class Dog {
get paws() {
console.log('paws!'); //side effect
this.paws++; // side effect
if(this.paws > 4) {
throw Error('oh no'); // side effect
}
return this.paws;
}
}
Every getter can alter the state of the app or break it while you are trying to debug it. That's why DevTools ask you to invoke these getters manually. Even if your getter returns a static value, DevTools have no way of knowing that.
If you really want to invoke all getters and have a quick overview of the values, you can create yourself a helper:
class Dog {
get _debug() {
return {
paws: this.paws,
//...
};
}
}
This will add a new getter that will invoke all other getters for you and give you their values with a single click (instead of n clicks).
You can work-around this, by running a script to auto-invoke the getters. To do this:
Open DevTools in a separate window.
Press CTRL+SHIFT+I
Switch to the console tab (of the devtools inspecting devtools)
Evaluate the below, and close the window
setInterval(() => {
[...document.querySelectorAll(".source-code")]
.map(s => [
...(s.shadowRoot?.querySelectorAll(
".object-value-calculate-value-button"
) || [])
])
.flat()
.forEach(s => s.click());
}, 500);
This will search for the invoke property button every 500ms. and click it for you.
I would like to synchronize the UI thread with changes in a view (pivot item 1 active view) which is active when the changes begin and switch to non active state (User interaction like changing the pivot item from the pivot item 1 to pivot item 2) before finishing the changes.
The changes never happens and the view is restored as the point when switching from active to non active state.
The UI stack composed from
ScrollViewer
Grid
List view
Grid
The grid controls contains progress bars to handle refresh
private async void scrollViewer_ViewChanged2(object sender, ScrollViewerViewChangedEventArgs e)
{
var listView = scrollViewer.GetDescendantsOfType<ListView>().FirstOrDefault();
var context = DataContext as IMainStreamViewModel;
if (e.IsIntermediate) return;
var dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
if (Math.Abs(scrollViewer.VerticalOffset) < 0.01 && _isPullRefresh)
{
// Adding item the Observable collection that is the
// the item source for the listview
// The method just add element using the core dispatcher
context.PullToRefreshInsertion_Top(dispatcher, listView);
}
else if (_scrollBar.Value >= _scrollBar.Maximum)
{
// same action but in bottom of the observable collection
// The method just add element using the core dispatcher
context.PullToRefreshAdd_Bottom(dispatcher, listView);
}
_isPullRefresh = false;
// Set the current element to be displayed in the list view
await dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() => listView.ScrollIntoView(listView.SelectedItem));
// Scroll to the the listview and hidding the progress control
await Task.FromResult(scrollViewer.ChangeView(null, 60, null));
}
Finally the element may be added but the scroll viewer dont reset his position and listview also
How to solve the sychronisation, i think the problem come from the IsActiveView state if the UI element is not in the ACTIVE VIEW it doesn't execute or skip the event.
UPDATE 1 :
The situation is as :
Pivot control that contain two pivot items :
Pivot item one contain :
***Scrollviewer
******Grid that contain a custom progress bar top refresh
******ListView containing the data that user can see and interact with
******Grid that contain a custom progress bar bottom refresh
Pivot item two contain some Richtextblock ...
When i'm doing the pull to refresh from the pivot item one and before the custom progress bar disappears do swipe to the next pivot item.
When i come back to the first pivot item, it was freezed at the state when i want to refresh and the top or bottom progress bar still visible.
I solved that by doing some trick and add some isVisible property in my view model and i fire the event whenever i'm in this pivot item i call updatelayout() and now it works.
I think the problem come from the fact when i'm doing swipe, the UI thread cancels all operations and start executing the operations attached to the active view this is why the update layout event for the first pivot item never fire.
In our App we have a log-in ViewController A. On user log-in, a request navigate is automatically called to navigate to the next ViewController B. However when this is done we want to remove the log-in ViewController A from the stack so the user cannot "go back" to the log-in view but goes back the previous ViewController before the log-in instead.
We thought about removing the ViewController A from the stack when ViewController B is loaded, but is there a better way?
In the Android version of the App we've set history=no (if I recall correctly) and then it works.
Is there an similar way to achieve this in MonoTouch and MvvmCross?
I ended up with removing the unwanted viewcontroller from the navigation controller. In ViewDidDisappear() of my login ViewController I did the following:
public override void ViewDidDisappear (bool animated)
{
if (this.NavigationController != null) {
var controllers = this.NavigationController.ViewControllers;
var newcontrollers = new UIViewController[controllers.Length - 1];
int index = 0;
foreach (var item in controllers) {
if (item != this) {
newcontrollers [index] = item;
index++;
}
}
this.NavigationController.ViewControllers = newcontrollers;
}
base.ViewDidDisappear(animated);
}
This way I way remove the unwanted ViewController when it is removed from the view. I am not fully convinced if it is the right way, but it is working rather good.
This is quite a common scenario... so much so that we've included two mechanisms inside MvvmCross to allow this....
a ClearTop parameter available in all ViewModel navigations.
a RequestRemoveBackStep() call in all ViewModels - although this is currently NOT IMPLEMENTED IN iOS - sorry.
If this isn't enough, then a third technique might be to use a custom presenter to help with your display logic.
To use : 1. a ClearTop parameter available in all ViewModel navigations.
To use this, simply include the ClearTop flag when navigating.
This is a boolean flag - so to use it just change:
this.RequestNavigate<ChildViewModel>(new {arg1 = val1});
to
this.RequestNavigate<ChildViewModel>(new {arg1 = val1}, true);
For a standard simple navigation controller presenter, this will end up calling ClearBackStack before your new view is shown:
public override void ClearBackStack()
{
if (_masterNavigationController == null)
return;
_masterNavigationController.PopToRootViewController (true);
_masterNavigationController = null;
}
from https://github.com/slodge/MvvmCross/blob/vnext/Cirrious/Cirrious.MvvmCross.Touch/Views/Presenters/MvxTouchViewPresenter.cs
If you are not using a standard navigation controller - e.g. if you had a tabbed, modal, popup or split view display then you will need to implement your own presentation logic to handle this.
You can't: 2. RequestRemoveBackStep().
Sadly it proved a bit awkward to implement this at a generic level for iOS - so currently that method is:
public bool RequestRemoveBackStep()
{
#warning What to do with ios back stack?
// not supported on iOS really
return false;
}
from https://github.com/slodge/MvvmCross/blob/vnext/Cirrious/Cirrious.MvvmCross.Touch/Views/MvxTouchViewDispatcher.cs
Sorry! I've raised a bug against this - https://github.com/slodge/MvvmCross/issues/80
3. You can always... Custom ideas
If you need to implement something custom for your iOS app, the best way is to do this through some sort of custom Presenter logic.
There are many ways you could do this.
One example is:
for any View or ViewModel which needs to clear the previous view, you could decorate the View or ViewModel with a [Special] attribute
in Show in your custom Presenter in your app, you could watch for that attribute and do the special behaviour at that time
public override void Show(MvxShowViewModelRequest request)
{
if (request.ViewModelType.GetCustomAttributes(typeof(SpecialAttribute), true).Any())
{
// do custom behaviour here - e.g. pop current view controller
}
base.Show(request);
}
Obviously other mechanisms might be available - it's just C# and UIKit code at this stage
I don't know about mvvm but you can simply Pop the viewcontroller (AC A) without animation and then push the new viewcontoller (AC B) with animation
From within AC A:
NavigationController.PopViewControllerAnimated(false);
NavigationController.PushViewController(new ACb(), true);
I have an application with a popup menu. I'd like to use the popup in the usual way (i.e., it should appear when the user right-clicks anywhere in the window), but I'd also like to attach it to the main MenuBar at the top of the window. I'm not sure how to do this.
I'd thought it would as simple as calling
myJMenuBar.add(myPopupMenu)
but this doesn't work.
JMenuBar.add() wants a JMenu parameter, not a JPopupMenu.
Does anyone have any suggestions?
Instead of trying to reuse the JPopupMenu object, the best approach would be to encapsulate the actions that the menus perform, and reuse those. The popup would trigger those actions, as would the menu items.
From the Action JavaDoc:
In addition to the actionPerformed method defined by the ActionListener interface, this interface allows the application to define, in a single place:
One or more text strings that describe the function. These strings can be used, for example, to display the flyover text for a button or to set the text in a menu item.
One or more icons that depict the function. These icons can be used for the images in a menu control, or for composite entries in a more sophisticated user interface.
The enabled/disabled state of the functionality. Instead of having to separately disable the menu item and the toolbar button, the application can disable the function that implements this interface. All components which are registered as listeners for the state change then know to disable event generation for that item and to modify the display accordingly.
and
JPopupMenu, JToolBar and JMenu all provide convenience methods for creating a component and setting the Action on the corresponding component. Refer to each of these classes for more information.
I had the same issue. A right-mouse-click as well as a top menu with exactly the same (complicated) set of menu items. The 'Action' class is something to consider if you are talking about enablement choices, but it's not dealing with visibility and in my case there was also a dynamic list of entries based on a current selection that I wanted to reuse.
So I ended up implementing a 'Bridge' design pattern (I think) for the methods I actually use (add() and addSeparator()):
public static class MenuBridge
{
private JPopupMenu popupMenu;
private JMenu menu;
public MenuBridge(JPopupMenu popupMenu)
{
this.popupMenu = popupMenu;
}
public MenuBridge(JMenu menu)
{
this.menu = menu;
}
public void addSeparator()
{
if(popupMenu!=null) popupMenu.addSeparator();
else menu.addSeparator();
}
public void add(JMenuItem item)
{
if(popupMenu!=null) popupMenu.add(item);
else menu.add(item);
}
}
So then I can write a reusable method that computes the menu items and synchronize my right mouse click with the top-level menu:
public void addTaskMenuItems(DefaultMenu menu, List<MDProcTask> taskList)
{
...
menu.add()/menu.addSeparator()
...
}
addTaskMenuItems(new DefaultMenu(popupMenu),taskList);
...
taskMenu.addMenuListener( new MenuListener() {
public void menuCanceled(MenuEvent menuevent)
{
}
public void menuDeselected(MenuEvent menuevent)
{
}
public void menuSelected(MenuEvent menuevent)
{
taskMenu.removeAll();
addTaskMenuItems( new DefaultMenu(taskMenu),getSelectedTasks());
taskMenu.revalidate();
}});
I was trying to filter a combo box dataprovider based on the values in the text boxes . When the contents of the dataprovider changes Combo box automatically calls change event method . Please find the sample code below.
Filter Utility Function:
private function filterLocations(event:FocusEvent):void {
locationsList1.filterFunction = filterUtility;
locationsList1.refresh();
}
public function filterUtility(item:Object):Boolean {
// pass back whether the location square foot is with in the range specified
if((item.SQUARE_FOOTAGE >= rangeText1.text) && (item.SQUARE_FOOTAGE rangeText2.text))
return item.SQUARE_FOOTAGE;
}
// THIS WOULD BE CALLED WHEN COMBO BOX SELECTION IS DONE
private function selectLocationsReports(event:ListEvent):void {
selectedItem =(event.currentTarget as ComboBox).selectedItem.LOCATION_ID;
}
When the DataProvider gets refreshed its automatically calls change method and was throwing Null Pointer function because its prematurely calling the above selectLocationsReports method and its throwing error.
Can somebody let me know how to stop the CHANGE event from propogation when the dataprovider is refreshed.
You can't stop a CHANGE event, just don't add an event listener unless you are prepared to get the event. I don't see where your event listener for Event.CHANGE is in the code above.
Just be sure that you don't addEventListener(Event.CHANGE, selectLocationsReports) until your ComboBox is ready for it.
The other thing to do (on top of Kekoa's response) is put an if statement in the event handler, and check to make sure the data is there before you begin working with it.
A handy syntax I use frequently for this is
if(dataprovidername) {
}