I have multi EditTexts.
How can i validate the EditText from having "" in the EditText and if the EditText is "" then i want the user to must enter a number before it goes to edittext2
How can this be done?
case R.id.P2Throw1Set2:
p212r.setText(String.valueOf(Integer.parseInt(p2score.getText().toString()) - Integer.parseInt(p212.getText().toString())));
p2score.setText(String.valueOf(Integer.parseInt(p212r.getText().toString())));
break;
case R.id.P2Throw2Set2:
p222r.setText(String.valueOf(Integer.parseInt(p2score.getText().toString()) - Integer.parseInt(p222.getText().toString())));
p2score.setText(String.valueOf(Integer.parseInt(p222r.getText().toString())));
break;
case R.id.P2Throw3Set2:
p232r.setText(String.valueOf(Integer.parseInt(p2score.getText().toString()) - Integer.parseInt(p232.getText().toString())));
p2score.setText(String.valueOf(Integer.parseInt(p232r.getText().toString())));
break;
case R.id.P2Throw4Set2:
p242r.setText(String.valueOf(Integer.parseInt(p2score.getText().toString()) - Integer.parseInt(p242.getText().toString())));
p2score.setText(String.valueOf(Integer.parseInt(p242r.getText().toString())));
break;
You're going to have to disable all but the first edit text and only enable them when the user has provided satisfactory input. Then wrap your parseInt() calls in try/catch blocks like so:
case R.id.P2Throw2Set2:
try
{
p222r.setText(String.valueOf(Integer.parseInt(p2score.getText().toString()) -
Integer.parseInt(p222.getText().toString())));
p2score.setText(String.valueOf(Integer.parseInt(p222r.getText().toString())));
// if the previous lines worked, this will work
p232r.setEnabled(true);
}
catch(NumberFormatException e)
{
// user entered "" or the value was null
// in this case, we leave the next edit text disabled
}
break;
A little bit late answer, but you might take a look onto the declarative form validation techniques and advanced validation implemented in the BARACUS framework for Android applications coping with the problems of validation in Android apps. Since the stuff is open source feel free to use source fragments coping with validation if you don't want to use a framework.
Related
I am trying to use Odoo with the application Barcode & QR code Keyboard, from Nikola Antonov (just an example, I do not know if there are better options), in order to read barcodes for the pickings.
The first problem I had to face was I had to show the keyboard in this picking view
So I needed to create an input field in order to click in it and show the Android Keyboard, or in this case the Nikola Antonov keyboard. Then, I had to assign the function handler to this input text field:
this.$('#input_text_barcodes').on('keyup', self.getParent().barcode_scanner.handler);
The function is only working as expected if I use the normal Android Keyboard (AOSP) and only with numbers. The letters of the Android Keyboard or whatever character of the Nikola Antonov Keyboard are not working (only the backspace)
this.handler = function(e){
self.$('#aux_label').text('>> CODE: ' + e.which)
self.$('#aux_label').text('>> KEY CODE: ' + e.keyCode)
self.$('#aux_label').text('>> KEY: ' + e.key)
// [...]
I tried switching the languages of the keyboard as well, but with the same result
Should I change the keyup event?
Is there other way to catch the characters?
Finally I have asked to the developer of the application directly and he solved the problem quite fast. He made it work with numeric keys, that is enough for what I wanted to achieve.
I'm working on Android project, I want to check whether the password and re-enter password does match or not if it doesn't I want to stop right there. I did:
System.exit(0);
this System.exit(0); function takes me to the different page but I want to stay where I am now.
break;
finish();
I tried break and finish they did not work either. any help would be appreciated.
Thank you very much for your time and assistance in this matter.
try this snippet code.
EditText passwordText = (EditText) findViewById(R.id.passwordText);
EditText rePassword = (EditText) findViewById(R.id.rePassword);
if(!passwordText.getText().toString().equals(rePassword.getText().toString())){
Toast.makeText(getApplicationContext(),"Password must same",Toast.LENGTH_LONG).show();
}else{
//do some thing.
}
hope it help
Situation: hammer.js 2.0.4, jQuery 2.1 on a Cordova cross-platform mobile app. I was running into well-documented (for example) issues with delay of click events, so I thought I'd try hammer.js for this. It works beautifully on my iPad, but on my Android phone (Android v4.4) is dreadful: very slow to respond, and frequently misses taps entirely.
I implemented my own small tap detection (using mouseUp events) and it performs much better than Hammer.js on my Android (but terribly on my iPad).
So my question is: are there known issues for hammer.js on Android, or known workarounds? I'd really prefer not to conditionally use two different approaches based on platform, especially when there is no conceivable way for me to test all possible mobile platforms.
Example of the hammer.js tap code; nothing very interesting going on:
$(".menuitem").each( function(i, elem) {
var mc = new Hammer.Manager(elem);
mc.add(new Hammer.Tap());
mc.on("tap", action);
});
In addition there is a top-level swipe recognizer that covers the entire page:
var swipelistener = new Hammer($("body")[0], {
recognizers: [[Hammer.Swipe,{ direction: Hammer.DIRECTION_RIGHT }]]
});
swipelistener.on("swipe", swipeRight );
In total there will be fewer than two dozen elements responding to tap events, and no overlapping or nested elements. I thought it might have something to do with the swipe recognizer overlapping the tap recognizers, but removing the swipe listener didn't change the tap behavior at all.
You need to play with the settings of each recognizer.
hammertime.get('swipe').set({
direction: hammer.DIRECTION_ALL, threshold: 1, velocity: 0.1
});
This worked for me for swipe on 4.1.1
Would be really helpful if someone could write some example code for tap as I'm still fiddling with that.
Also, you don't need mc.add as the Manager by default has all the recognizers. You only need to use .add once you've manually removed (using mc.remove) one.
If you are unsure what settings any of the recognizers have, look on their website eg http://hammerjs.github.io/recognizer-swipe/ shows that I could set direction, threshold and velocity etc as per the code above.
As I can see you need to detect swipe on entire screen without any specific options. Maybe cordova-android-gestures (only for Android) helps you? This plugin "catches" gestures on total device surface. So, for detect swipes:
//check the platform
if (device.platform=="Android") {
MegaduckGestures.swiper(function(direction){
switch (direction) {
case 'rightSwipe':
//do your staff
break;
case 'leftSwipe':
//do your staff
break;
default: break;
}
});
}
else {
//use your iPad approach
}
And for handling tap on menu item:
$(".menuitem").each( function(i, elem) {
//check the platform
if (device.platform=="Android") {
MegaduckGestures.swiper(function(direction){
if (direction=='singleTap') {
//do your staff
}
});
}
else {
//use your iPad approach
}
});
I'm creating a mobile app for a medical clinic that has 4 offices/buildings. I'd like to create a Google map that marks all 4 locations, and gives the user option to get directions to each location.
I'm building this app in Phonegap and Jquery mobile. The closest thing I have found so far is this: Direction example .
I would also like the "from" field default to user's location if GPS is enabled or using geolocation.
What are the common practices to do this (from usability point of view)? And do you know any resources I can refer to?
For using gps in your project you can use the code below
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
function (position) {
// Did we get the position correctly?
// alert (position.coords.latitude);
// To see everything available in the position.coords array:
// for (key in position.coords) {alert(key)}
mapServiceProvider(position.coords.latitude,position.coords.longitude);
},
// next function is the error callback
function (error)
{
switch(error.code)
{
case error.TIMEOUT:
alert ('Timeout');
break;
case error.POSITION_UNAVAILABLE:
alert ('Position unavailable');
break;
case error.PERMISSION_DENIED:
alert ('Permission denied');
break;
case error.UNKNOWN_ERROR:
alert ('Unknown error');
break;
}
});
}
Which can be found here or the phonegap docs
When you have the location you can change the value of
your form. Then there is the question of using a plugin
of google maps or not. Personally i didn't use any. Since
you are using jquery mobile you can use this .
Create the map in the init event (so you create only once) and
trigger the resize event in the pageshow event so you will not have problems
with the map appearing on the upper left corner of your screen etc.
If you use the plugin I mentioned, look for the refresh method.
The container of the map must have a size. If it doesn't it
will not show properly because jqm will give the minimum size
to the container. You can do it programmatically (check for
window height and width) and calculating the space (if there is
a header you have to include it in the calculation).
Finally if you are having problems with zoom look at this
Check out this post about Google Maps inside jQuery Mobile. I think this solves your issue.
Can someone point me in the right direction - I'm trying to create an Android Activity that looks like a technical manual that ALSO can take some user input(I know how to do simple buttons etc.) and the user input part can wait until I have a few basic pages.
My goal (if possible) would be to create a text-heavy activity (like a technical manual) but I'm not sure what the best GENERAL method is for doing this.
To start - rather than having multiple activities I want one large activity that a User may be able to swipe through from left to right (Perhaps use ViewFlipper here??)
But how can I make an Activity that looks like a manual or is Text Heavy??
Thanks!
This is what I did with my application's instructions. I started with ViewFlipper that has next and back buttons. Then as the application grew in size, code got messier and there are a lot of formatting that I needed for the text. So I turned to use WebView and just store the text files as raw assets.
WebView manual=new WebView();
manual.loadData(Utilities.getData(this, R.raw.update),"text/html", "utf-8");
getData method:
public static String getData(Context c,int res) throws IOException{
InputStream ins = c.getResources().openRawResource(res);
byte[] buffer = new byte[ins.available()];
ins.read(buffer);
ins.close();
String html=new String(buffer);
StringBuilder buf = new StringBuilder(html.length());
for (char c1 : html.toCharArray()) {
switch (c1) {
case '#': buf.append("%23"); break;
case '%': buf.append("%25"); break;
case '\'': buf.append("%27"); break;
case '?': buf.append("%3f"); break;
default: buf.append(c1);
break;
}
}
return buf.toString();
}
Then you can attach buttons either to the webview or the application in response to user inputs and load new views.
Advantage:
1. Easy to format and integrate with Android. Very quick development.
2. No need to worry about the view flipper bugs that happens sometimes.
3. It will look like you want.
Disadvantage:
1. Doesn't look too much like an Android Application by itself.