Continuous Pagination with LongListSelector - windows-phone-8

When my LongListSelector is scrolled to bottom, I want to automatically load more data from a web service. Just like the Store app does. My problem is that I can't found any event to trigger the load more action.

The recommandation from Microsoft is to use the LongListSelector.ItemRealized event, check if it's the last item (or the Nth last item) in the list to be "realized" and if it is, then it will start fetching new records. In terms of UX, it's best to show a ProgressIndicator on the SystemTray at the time and not try to imitate iOS with inline spinners.
LongListSelector.ItemRealized is actually a very interesting event since it fires when an Item has been data bound to a virtualized ListBoxItem. That means that the LongListSelector virtualization logic thinks it needs to prepare the FrameworkElement to be shown on screen. The ListBoxItem may or may not be on screen yet, but it's a good indication it's getting there.
For a code sample see # http://code.msdn.microsoft.com/wpapps/TwitterSearch-Windows-b7fc4e5e
void resultListBox_ItemRealized(object sender, ItemRealizationEventArgs e)
{
if (!_viewModel.IsLoading && resultListBox.ItemsSource != null && resultListBox.ItemsSource.Count >= _offsetKnob)
{
if (e.ItemKind == LongListSelectorItemKind.Item)
{
if ((e.Container.Content as TwitterSearchResult).Equals(resultListBox.ItemsSource[resultListBox.ItemsSource.Count - _offsetKnob]))
{
Debug.WriteLine("Searching for {0}", _pageNumber);
_viewModel.LoadPage(_searchTerm, _pageNumber++);
}
}
}
}

Related

Weird behavior while Suppress "Bookmarks" button in SAPUI5, Fiori

Some times ago i've successfully suppressed the "Save as Tile" button that exists in the Standard Fiori App, MM_PO_APV:
// Standard application buttons (Remove Forward)
this.setHeaderFooterOptions({
oPositiveAction: {
sI18nBtnTxt: that.resourceBundle.getText("XBUT_APPROVE"),
onBtnPressed: jQuery.proxy(that.handleApprove, that)
},
oNegativeAction: {
sI18nBtnTxt: that.resourceBundle.getText("XBUT_REJECT"),
onBtnPressed: jQuery.proxy(that.handleReject, that)
},
onBack: jQuery.proxy(function() {
//Check if a navigation to master is the previous entry in the history
var sDir = sap.ui.core.routing.History.getInstance().getDirection(this.oRouter.getURL("master"));
if (sDir === "Backwards") {
window.history.go(-1);
} else {
//we came from somewhere else - create the master view
this.oRouter.navTo("master");
}
}, this),
// Remove the 'Save as Tile' button
bSuppressBookmarkButton : true
});
But they had updated the SAPUI5 version, I think the lastest, and it comes with a problem. The button is appearing, but with a weird behavior, as you can see:
All my code remains the same, and as I've seen on documentation API, it remains the same too.
Could you help me on how to resolve this?
Regards,
Andre
The most likely cause for this would be the UI5 version(the latest update that you mentioned).
Try one of these two things,
Clear cache and re-run the application
Revert to a previous UI5 version or update to a new version
Contact the respective support team(Scaffolding team I assume) if these don't help.
This should work:
//Prevent overflow button (...) in footer
this.oApplicationImplementation.oDHFHelper.oCommonHeaderFooterHelper.bAutomaticOverflow = false;
Put this code in the onInit method of the controller extension.

LWJGL Mouse carrying out command multiple times randomly

Im trying to set my LWJGL Mouse to grabbed and not grabbed when i push the left mouse button.
However this has proven to become a tricky matter since the LWJGL mouse for some matter executes the command multiple times randomly. For an example:
if (Mouse.isButtonDown(0)){
Mouse.setGrabbed( !Mouse.isGrabbed() );
System.out.println("Pushed");
}
if(Mouse.isGrabbed()){
camera.processMouse(1, 80, -80);
If i run this code it will print "Pushed" several times randomly per push. As you can imagine that becomes a problem when i try to set my Mouse to grabbed true or false from each click. the times i have tried this code it has printed "Pushed" 4 - 7 times per click
is there any way to make the Mouse only carry out the command once per click?
many thanks in advance to everyone who will take time to help me solve this problem.
Thomas
An easy way is to check a boolean field which you flip on the first iteration of the block after the mouse is clicked or released to tell you if this is the first time since the click that the if block has been executed. Here's an example:
private boolean alreadyClicked;
void someMethod(){
if(Mouse.isButtonDown(0)){
if(!alreadyClicked){
alreadyClicked = true;
// do what you want to do when the mouse is clicked
}
}
else{
alreadyClicked = false;
}
}
Alternatively you could use the event buffer of the Mouse class to detect clicks like this:
while(Mouse.next()) {
if(Mouse.getEventButton() == 0) {
if(Mouse.getEventButtonState()) {
// clicked
}
else{
// released
}
}
}

SmartGWT TabSet.destroy() and recreation

I was having ID collision of tab IDs when trying to recreate the same TabSet.
My case is the following : I have 3 Tabs in general, then some action creates a 4th one, some action happens in this 4th tab which is then closed, and I need to relaunch my app and redraw again the 3 general Tabs fetching new info from the database. Everything was working well, except this warning of collision which was not a blocking one anyway.
In order to clean it, I followed Isomorphic's advice from this thread
and tried destroying the TabSet in order to recreate it.
I do:
if (myTabSet != null) {
myTabSet.destroy();
}
myTabSet = new TabSet();
// setting TabSet properties
// creating Tabs and adding them to the TabSet
I noticed, however, in debug, that the TabSet is not being desroyed completely, just some of its properties, and that a new ID is being given to it. As a result, there are no more warnings, the tabs are created, but they're not populated.
My question is : why the TabSet is not becoming null upon destruction, and how can I recreate it with no collision of IDs?
Thanks in advance
I used to have the same problem and fixed it with:
myTabSet.addCloseClickHandler(new CloseClickHandler() {
#Override
public void onCloseClick(TabCloseClickEvent event) {
event.getTab().getPane().destroy();
}
});
Apparently the tabset is not completely destroyed unless you destroy its pane.
Maybe it will work for you !

Unable to refresh JTabbedPane

I am using JTabbedPane with JPanel to display JTable on one tab and text, dropdown and jbutton on other tab.
First time it is working fine but if i minimize or switch screen to other application and come back to my application it display data correct but with a serious problem with tab change in JTabbedPane. Now tab screen goes to blue and don't display the data.(I hope data is there but it is not repainting or refreshing complete window).
Now with blue screen i do the same procedure and change tab in JTabbedPane it shows correct data.
I used repaint but it doesn't work.
Help needed to refresh window or tab correctly.
It may problem of Browser you are using jdic.dll. Try using any other browser to reload your tabbed pane.
I guess this "issue" is an evergreen. I assume, that most people stumble over this issue possibly when implementing JTabbedPane changes (removing and adding of tabs) in the wrong event-method:
For example, if you want to remove a tab and add a new one in the tabbed pane based on a selection in a JComboBox, you have to put your logic into an 'itemStateChanged'-event of the ItemListener added to this combo-box. If you put your tab-change-logic e.g. into an propertyChangeEvent (PropertyChangeListener), you are doing it all wrong and the timing is always messed up for repainting/refreshing tabbed pane UI elements!
If you use the right event-method, you don't even have to call setVisible, revalidate nor repaint. It will all work out perfectly.
Here's a simple example:
JComboBox<String> c_editor = new javax.swing.JComboBox<String>();
c_editor.setModel(new javax.swing.DefaultComboBoxModel<>(
new String[] { "CSV", "EXCEL", "HTML" }
));
c_editor.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
c_editorItemStateChanged(evt);
}
});
...
protected void c_editorItemStateChanged(ItemEvent evt) {
// get the value selected in the combo box
final String val = c_editor.getSelectedItem().toString();
if (tabbed_pane.getTabCount() > 1) {
// remove the panel which is at position 1
tabbed_pane.removeTabAt(1);
}
if (val.equals("CSV")) {
// add the panel for viewing CSV files
tabbed_pane.addTab("CSV Editor", p_csv);
} else if (val.equals("EXCEL")) {
// add the panel for viewing Excel files
tabbed_pane.addTab("Excel Editor", p_excel);
} else if (val.equals("HTML")) {
// add the panel for viewing HTML files
tabbed_pane.addTab("HTML Editor", p_html);
}
}
That's all, nothing else necessary - the UI will update itself. PS: This issue has nothing to do with browsers as suggested by the 'favoured' answer in this thread, it's all about Java Swing GUI's.

GUI for sentence alignment tasks

Can someone introduce me on how to write a simple web (HTML/XML) interface for a simple sentence alignment task?
The task is as follows:
The 1st line of the webpage would be the English sentence that will need to be matched to the chinese sentences below:
000325EN Whatever goes upon two legs is an enemy.
(checkbox)001054ZH 凡靠两条腿行走者皆为仇敌;
(checkbox)001055ZH 凡靠四肢行走者,或者长翅膀者,皆为亲友;
(checkbox)001056ZH 任何动物不得着衣;
(checkbox)001057ZH 任何动物不得卧床;
(checkbox)001058ZH 任何动物不得饮酒;
(checkbox)001059ZH 任何动物不得伤害其他动物;
(checkbox)001060ZH 所有动物一律平等。
(checkbox)Nil No matching sentence
(submit button) (clear selection button)
The user should be able to click 1 or more of the check boxes.
When the submit button is clicked the webpage will save a line in a appendable textfile in the format
SentID<\TAB>#English_sentence<<\TAB>SentID2<\TAB>=Chinese_sentence (e.g.:
000325EN #Whatever goes upon two legs is an enemy. 001054ZH =凡靠两条腿行走者皆为仇敌;
if there are more than 1 match to the English sentence, it may look like this
000325EN #Whatever goes upon two legs is an enemy. 001054ZH =凡靠两条腿行走者皆为仇敌; 001055ZH =凡靠四肢行走者,或者长翅膀者,皆为亲友;
Depending on what should happen with the stored data, it indeed is possible to store them on the client, without any server-side scripting, see the HTML5 local storage facility: https://developer.mozilla.org/en/dom/storage (including example for degradation to cookies).
A good starting point for getting into locally stored data with HTML5 is http://diveintohtml5.ep.io/storage.html.
A simple example taken from http://msdn.microsoft.com/en-us/library/cc197062(v=vs.85).aspx#_global and enhanced with localStorage detection from the link above:
<p>
You have viewed this page
<span id="count">an untold number of</span>
time(s).
</p>
<script>
function supports_html5_storage() {
try {
return 'localStorage' in window && window['localStorage'] !== null;
} catch (e) {
return false;
}
}
if (supports_html5_storage()) {
var storage = window.localStorage;
if (!storage.pageLoadCount) storage.pageLoadCount = 0;
storage.pageLoadCount = parseInt(storage.pageLoadCount, 10) + 1;
document.getElementById('count').innerHTML = storage.pageLoadCount;
}
else {
alert('No local storage available!');
}
</script>
First of all....
The user should be able to click 1 or more radio buttons
Radio buttons were designed to only allow one button at a time selected. Perhaps you mean to use a checkbox instead?
the webpage will save a line in a appendable textfile
This is impossible to implement without using a server-side language (such as PHP, Ruby, Python, etc.).
Thirdly, you need to specify exactly what you want. What exactly is supposed to happen when the "submit button is clicked"? What do you mean by "sentence alignment"?