Phonegap - jquery Mobile : button click event not able catch in android - android

I am developing a sample app using phonegap with the jQuery mobile plugin for android. I created a page, main.html. From main.html, I am able to catch the event. Once button is pressed in the main page, I change the contents using( $.mobile.changePage("path") ) function to signup.html. I have button in signup.html but when I click that button click event does not get fired. I have loaded all the js file in signup.html as well. what am doing wrong? Please guide me.
Clarification: Should I keep only one html (main.html ) and through that I have to do page navigation.?

In case your second page javascript is placed inside a HEAD content
If I understood you correctly, you are using ajax to load this page into the DOM? If this is true then I understand your problem. You see, when ajax is used for page loading only BODY content is loaded into the DOM.
You can fix your problem if you initialize your second html page javascript inside a first HTML file or move your SCRIPT block inside a second HTML BODY content.
Also, I have described this problem in my other ARTICLE with more details and few examples, or it can be found HERE.
In case you have several buttons with a same id
This could also be a little different problem. You see, if you have 2 buttons with a same id, they are both inside a DOM structure. If you try to bind a click event on a second page button, that same event will be bound to the button on a first page. Because they have a same id jQuery will bound an event to the first button (with that id) found in the DOM.
To fix this problem you need to use a jQM constructor called active page. One more warning, next code example will work only in a page events initialized after a pageinit event, for example pagebeforeshow or pageshow events:
$(document).on('pagebeforeshow', '#yourPageID', function(){
// Registering button click
$(document).on('click', $.mobile.activePage.find('#myButtonID'), function(){
// Do something
});
});
This line of code:
$.mobile.activePage.find('#myButtonID')
Will only get button '#myButtonID' found in a current active page, no matter how many other buttons with a same id exist inside the DOM.
Answer to the last question
About your last questions. It doesn't matter which template structure you use (1 HTML with multiple pages or multiple HTML's), you just need to worry about things I mentioned before.

Did you wrap your code inside following snippet?
$(document).on('pagebeforeshow', '#yourPageID', function(){
// Registering button click
$('#myButtonID').bind('click',function(){
$.mobile.changePage('yourfile.html');
});
});
if you just wrap it inside your <script></script> tag the event will not fire.
Did you get any error in the console? Check DDMS for it.

Related

Navigation NavController in Ionic 2 app SOLVED! but not in Ionic 3

I'm building an app with Ionic 2 and my question relates the navigation, it is not easy to explain but I'll try:
I have a page (MyFilePage), with a list of files from a cloud, in which I recall the navCtrl.push() on it, for recursive navigation in folders. On this page I have an ion-fab button who sends me, with push(), to another page (UplaodPage), with the list of file in the memory's device. In this page I recall the method push() on it, as the other page, for recursive navigation in folders. After that I select the file I want to upload, and what I would to do, is return to the last MyFilePage visited, (the one where I make the uplaod).
I post an image, ionic 2 app strucure , that may clarify the situation.
Thanks
EDIT:
This works nice on Ionic 2 with the method push(page: any, params?: any, opts?: NavOptions, done?: Function);, but not in Ionic 3, that have the method push(page: Page | string, params?: any, opts?: NavOptions, done?: Function): Promise;, where page is type of Page|string and the method getByIndex() returns a ViewController.
Anyone have a solution? Thanks
If you want to keep pages:
1- first you need to get the index of the page you want to back to and save in a provider(recommended) or storage.
let index = this.navCtrl.indexOf(this.navCtrl.getActive());
2- then you can go to the saved page like this:
let selectedPage = this.navCtrl.getByIndex(index);
this.navCtrl.push(selectedPage );
and if you like to remove those pages:
1- first you need to get the index of the page you want to back to and also a counter when ever you push a page. then save them in a provider(recommended) or storage.
2- then you can go to the selected page and remove the other like this:
this.navCtrl.remove(startIndex+1, removeCount);
for more info check NavController.

Not able to click on an element in Appium

My UI Automator Viewer Screenshot
I want to click on Play Now button and tried the following code:
driver.findElement(By.xpath("//android.view.View[contains(#content-desc,'Play Now')]"));
and this code:
driver.findElement(By.name("Play Now!"));
These codes are not showing any error but not clicking on Play Now button even.
Please help.
try this one
driver.findElementByAccessibilityId("content written on the button").click();
If you feel your Xpath is right but you are not click on that means that is because of synchronization problem. Just give time to find the element and click. Try like below example
Thread.sleep(5000);
driver.findElement(By.xpath("//android.view.View[contains(#content-desc,'Play Now')]")).click();
Thread.sleep(5000) gives 5 second time to search for the element. This should work in your case.
if click works fine not need to use any waits.
You can further use implicit or explicit wait once you are perfect with your automation.

Problems with Listpicker App Inventor

I'm a beginner at App Inventor and I don't know what I'm doing wrong with the listpicker.
I am trying to create and app to reproduce the music I have stored in my server but when i display the listpicker I can't click any of the options and also I can't go back to the first screen. Here I put my code:
Image 1
Image 2
I tried to remove the line that says call listpicker.open but it only made appear a totally black screen.
The result of the code I just posted is exactly what I spect a list with the name and the link of the 2 songs I already upload to my server but when I click them it didn't do anything.
Thanks for your help.
The Web component works asynchronously, which means, it takes a little bit, until the result is available. The result you will get in the Web.GotText event.
Therefore it does not make sense to call the updateListpicker procedure in the Listpicker.BeforePicking event, because the result still is not available and you get displayed an empty listpicker. The listpicker will be opened, before you have received the result!
Set the listpicker to visible=false and use a button.click event to call the updateListpicker procedure. Then as you already do it in the Web.GotText event, assign the received list to the listpicker and open it.

Appcelerator Alloy: remove a window from memory after opening another

I'm writing an Android app using Titanium Alloy.
This app has multiple View files and it is based on a lot of Windows elements.
Just for making a simple example, think about this:
I have two View files: index.xml (with its Controller index.js) and win02.xml (with its Controller win02.js). index.xml has a Button. I want to open win02 from index by pressing its Button and I want everything about index to be removed from memory so I avoid possible memory leaks.
Inside index.js, I put this code:
btn.addEventListener('click', function(e){
Alloy.createController('win02').getView().open();
});
And, in doing so, I am able to open the win02 Window. But how can I totally remove index? Thanks.
To remove a window you can call close() so $.index.close(); just after you create win02, that should do the trick.

Issue with webview

In my application i use a mix of html and native. In my web view i load a html page which has a which has an image in it. On click of the image i call a java script function which in turn calls the native code. My html tag is as below:
<img onclick=nextLevel('0'); id="d2">
My javascript method is as below:
function nextLevel(index)
{
Android.displayNextLevel(index);
}
Within the displayNextLevel method i start the next activity. The issue is when i click on the image on the html page multiple times the event gets triggered multiple times and the activity opens up multiple times. Am i missing out on something? How do i overcome this issue? Kindly help me with this. Thanks in advance.
I guess you could fiddle around in the html/js to make sure you can only click it once every now and then.
You could also ditch your function and instead use the JavascriptInterface so you can handle stuff in your Java code instead.

Categories

Resources