last day (14 days later) » 

5:57 AM
0
A: Adding Validations to Registration form in android

HariharanTry this.. Use .trim() for every getting text from EditText fields like below.. String postalcode = mPostalcode.getText().toString().trim(); String password = mpass.getText().toString().trim(); And checking String length for your postalcode and password like below if(!(password.length() >= ...

 
hiii...I have tried to include android:inputType="phone" or android:inputType="number",But when i am executing this application the field is accepting characters also.how to restrict the field to numbers..Please suggest
 
@user3736518 Just use android:inputType="number" that will restrict the field to numbers
 
I have tried but the field is accepting characters also
 
@user3736518 that's not possible. Can you post that EditText code.
 
<EditText android:id="@+id/epostalcode" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:inputType="number"/>
how to limit these values to particular range..like for example if I want to enter the age within 5 to 100.how to do that.Please help
 
5:57 AM
@user3736518 Use the spinner to select the age.
 
the value of age is which we are extracting is in the from of string ,I converted the string value into integer and then i have given a range,like int age1-Integer.parseInt(age).but i am getting exception while validating..how to validate this
 
@user3736518 you can display that in string format also.
 
how?
please provide any sample code
 
spinner will allow string laso
 
okay...but for all the other fields i cant use spinner..actually i am creating a medical app..which consits of blood glucose reading blood sugar reading..which has some range...for everything i cant give spiiner
 
6:02 AM
user need to enter value
 
Is that data's from backend
 
should i post my code?
package com.example.app;

import java.util.Calendar;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
android:id="@+id/bloodglucose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
see this is my coode
in blood glucose reading i want to limit the range between 80 to 160
 
while clicking save button you need to check.
right
 
6:08 AM
String BloodGlucose = mBgreading.getText().toString().trim();
int int_glucose = Integer.parseInt(BloodGlucose);
 
how to give range
i have tried like this
i m getting error
:(
 
if(int_glucose >= 80 && int_glucose <= 160){
}
 
okay let me try once again
 
check it and tell me.
 
NOT WORKING
even though i am giving input as 23 ,its accepting
and when i am not giving any input to the field i am getting an exception
07-15 02:16:21.160: E/AndroidRuntime(2001): FATAL EXCEPTION: main
07-15 02:16:21.160: E/AndroidRuntime(2001): Process: com.example.app, PID: 2001
07-15 02:16:21.160: E/AndroidRuntime(2001): java.lang.NumberFormatException: Invalid int: ""
07-15 02:16:21.160: E/AndroidRuntime(2001): at java.lang.Integer.invalidInt(Integer.java:137)
07-15 02:16:21.160: E/AndroidRuntime(2001): at java.lang.Integer.parseInt(Integer.java:358)
07-15 02:16:21.160: E/AndroidRuntime(2001): at java.lang.Integer.parseInt(Integer.java:331)
 
6:18 AM
Hmm k Post the new code inside case R.id.save:
 
package com.example.app;

import java.util.Calendar;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
dis one is the updated code
 
if(!BloodGlucose.equals("")){
}]
if(!BloodGlucose.equals("")){
}
wait i'll post it clearly.
 
okay
 
if(!BloodGlucose.equals("")){
int int_glucose = Integer.parseInt(BloodGlucose);
if (!(int_glucose >= 80 && int_glucose <= 160)) {
invalid = true;
Toast.makeText(getApplicationContext(), "Please valid reading", Toast.LENGTH_SHORT) .show();
}
}
Instead of this
else if (int_glucose >= 80 && int_glucose <= 160) {
invalid = true;
Toast.makeText(getApplicationContext(),
"Please valid reading", Toast.LENGTH_SHORT)
.show();
}
Try that.
use Integer.parseInt(BloodGlucose); inside if condition.
 
okay
jst a sec
its not giving any error but its not switching bck to the next page
 
6:31 AM
Why you are using invalid boolean.
Is there any necessary for that.
 
actully i have tried jst
firstly i m assuming that vrything tfield should be filled
if its any field is left blnk then invalid is becoming true
 
No need that remove that if condition execute then else won't execute just use
else
{

addEntry(BloodGlucose, Meal, MealType, ListMedication, ListFood, Notes,
Date);
getBloodSugar();
Intent i_register = new Intent(AddBloodSugarInfo.this,
BloodSugar.class);
startActivity(i_register);




// finish();
}
 
oky i will try
 
7:12 AM
Are you there?
Is that working?
 
7:43 AM
so i cudnt reply iu bck
sorry sudnly my manger came
i am still facing the same problm
u dere???
 

last day (14 days later) »