I have a register form. i need to save the content in db. my data are saved successfully. but when i use space or some special characters my datas are not stored in db. what should i use to store the special characters and space in db,
if (Name.getText().toString().equals("")) {
Name.setError("Enter your name");
Name.requestFocus();
} else if (Dob.getText().toString().equals("")) {
Dob.setError("Enter Date of Birth");
Dob.requestFocus();
} else if (Collegeid.getText().toString().equals("")) {
Collegeid.setError("Enter your CollegeID");
Collegeid.requestFocus();
}
else {
String sname = Name.getText().toString();
String dob = Dob.getText().toString().trim();
String cid = Collegeid.getText().toString().trim();
}
Refer the screenshot above
Try to use [] brackets in the SQLite statements. It allow to you to add anything what you want.
Related
I want to make sure that time is not same.
It's an appointment booking app, so it cannot be the same.
public void clients()
{
String name=t2.getText().toString().trim();
String gender=t1.getText().toString().trim();
String barber=t4.getText().toString().trim();
String dt=t5.getText().toString().trim();
String concerng=t6.getText().toString().trim();
if(!TextUtils.isEmpty(name) || !TextUtils.isEmpty(gender) || !TextUtils.isEmpty(barber) || !TextUtils.isEmpty(dt) || !TextUtils.isEmpty(concerng))
{
String id=databaseReference.push().getKey();
client client=new client(id,name,gender,barber,dt,concerng);
databaseReference.child(id).setValue(client);
Toast.makeText(this, "", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(this, "Something Went Wrong Please Check Again", Toast.LENGTH_SHORT).show();
}
To be able to compare two dates, you need to store the values of the cdatetime property as a timestamp and not as a String, as I see in your database now. Here you can find how to add and retrieve a timestamp from a Firebase database. If you follow those steps, you'll be able to compare very easy two long primitives.
I have a database table in my android app. I want to compare database table name with a particular string.
Here is my code
if(branchName == TABLE_NAME)
{
}
else
{
Toast.makeText(this,"table not available",Toast.LENGTH_LONG).show();
}
Here branchName is the string.TABLE_NAME is a static string and it is the name of the table.
Whenever I run this code, control goes to else part and shows the toast message.
Why? How can I fix that?
for comparing two string you must use equal or equalsIgnoreCase ... ...
if (branchName.equalsIgnoreCase(TABLE_NAME) ){
// do sth
}
else{
Toast.makeText(this,"table not available",Toast.LENGTH_LONG).show();
}
try this way.
I'm developing Android App for a website which is Prestashop base.
When I'm signing in the user with email, I receive following value for Password field.
"passwd": "$2y$10$UwXekiYUoeH7K8rpi9YxKerHxHQZacMSIG3VKseVQ2fjlGlFRfN4W",
All I want to do is, just compare this value with a String(value from password EditText).
After successful comparison, I'll be able to Login the user.
Please help me! how can encrypt String value, to compare with above value?
(or is there any technique to decrypt above password value?)
You can use String1.equals(String2) in a if else statement to get this done.
String1 = received password value;
String2 = edittext.getText().toString; //value from edit text.
if(String1.equals(String2))
{
//Login sucessfull
}
else
{
//Failed
}
Decoding:
String password = "$2y$10$UwXekiYUoeH7K8rpi9YxKerHxHQZacMSIG3VKseVQ2fjlGlFRfN4W";
byte[] tmp2 = Base64.decode(password);
String val2 = new String(tmp2, "UTF-8"); // here you will get the decoded value.
I have built an app where I loop through and collect the users phone contacts, my aim is to then use these numbers and query my parse database and look for records that contain the users contacts (this will be to check if any of the users contacts are a user of my app, a users phone number will be saved to my parse database when they register). The problem I've got is that when collecting the users contacts numbers they are returned in different formats, some +447966000000, some 07966000000, some 07 966000 000000, etc.
My question is, what would be the best way to format my numbers when saving them to the database and retrieving them from the users contacts so that all numbers are saved and retrieved in the same format so that when I do a conditional check on them they will be easy to compare?
I have downloaded phone Number Utils library but I am not sure what in the library could be used to do something like this.
Code so far:
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
while (phones.moveToNext())
{
String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Toast.makeText(getApplicationContext(),name + " " + phoneNumber, Toast.LENGTH_LONG).show();
}
phones.close();
You can use PhoneNumberUtils.compare to compare and check if they are same or not.It returns true if they are same ignoring country codes etc.
Example:
PhoneNumberUtils.compare(context, 1234567890, +911234567890);
returns true
I have done it for Indian mobile number format
private String getNumber(String moNumber) {
Pattern special = Pattern.compile ("[!##$%&*()_+=|<>?{}\\[\\]~-]");
if (moNumber.isEmpty()||moNumber.length()<10) {
MydebugClass.showToast(getContext(), "Please input valid Number");
return null;
}else if (moNumber.length()>10 && !special.matcher(moNumber).find()){
String[] number=moNumber.split("");
StringBuilder stringBuilder=new StringBuilder();
for(int i=moNumber.length();i>moNumber.length()-10;i--){
stringBuilder.append(number[i]);
}
String reverse=new StringBuffer(stringBuilder).reverse().toString();
return reverse;
}else if(moNumber.length()>10&&special.matcher(moNumber).find()){
String numberOnly= moNumber.replaceAll("[^0-9]", "");
String[] number=numberOnly.split("");
StringBuilder stringBuilder=new StringBuilder();
for(int i=moNumber.length();i>moNumber.length()-10;i--){
stringBuilder.append(number[i]);
}
String reverse=new StringBuffer(stringBuilder).reverse().toString();
Log.d("mobilenumberspecial",reverse);
return reverse;
}
else {
return moNumber;
}
return null;
}
This is my code and I want to save date into my database and want to get saved into list.How do we can store date in database? how can we save date like int or String? It is showing curly red line below "datePickerBtn1", "datePickerBtn2", "datePickerBtn3". I have used button to show date dialogs but I want to store date as text in list. i am trying to make Notepad or task reminder.
case R.id.savebutton:
String subject = editsubject.getText().toString();
String description =editdescription.getText().toString();
int created = datepickerbtn1.getText().toString(); //save into database and get list
int due = datepickerbtn2.getText().toString();
int completed = datepickerbtn3.getText().toString();**
if(!subject.equals("") || !description.equals("")) {
Database_List db = new Database_List(this);
db.addList(subject, description, created, due, completed );
}
break;
I was wondering how could you compile your code with these lines in code
int created = datepickerbtn1.getText().toString(); //save into database and get list
int due = datepickerbtn2.getText().toString();
Please change this to
String created = datepickerbtn1.getText().toString(); //save into database and get list
String due = datepickerbtn2.getText().toString();
And you can store date as string or as DATE field. For simplicity store is as String.