This question already has answers here:
Android getText from EditText field
(6 answers)
Closed 6 years ago.
What went wrong? The data stored in firebase database are all wrong, which are totally different with my inputs in EditTexts.
public void createToUserProfile(){
String firstName = etFirstName.toString().trim();
String lastName = etLastName.toString().trim();
String mobilePhoneNumber = etMobilePhoneNumber.toString().trim();
String iDNumber = etIDNumber.toString().trim();
String year = etYear.toString().trim();
String month = etMonth.toString().trim();
String day = etDay.toString().trim();
String dateOfBirth = year+"/"+month+"/"+day;
String country = etCountry.toString().trim();
String province = etProvince.toString().trim();
String city = etCity.toString().trim();
String postCode = etPostCode.toString().trim();
String address = etAddress.toString().trim();
Firebase ref = new Firebase(Config.USER_URL);
UserP newUser = new UserP();
newUser.setFirstName(firstName);
newUser.setLastName(lastName);
newUser.setMobilePhoneNumber(mobilePhoneNumber);
newUser.setiDNumber(iDNumber);
newUser.setDateOfBirth(dateOfBirth);
newUser.setCountry(country);
newUser.setProvince(province);
newUser.setCity(city);
newUser.setPostCode(postCode);
newUser.setAddress(address);
ref.child("UserP").setValue(newUser);
}
The Firebase Console stored data shows as following:
Data stored wrong in Firebase Database
I recall this same issue from a previous post of yours.
An EditText has a toString() method inherited from View that returns a string dump of the view's properties. You are mistakenly calling that. To get the string the EditText contains, you need to call getText().toString().
Related
I have this structure in my Database inside the UserID I have this random ID which I declared when adding data to database I don't know how to call that to display the info inside to recycler view. Actually I can display the info in Recyclerview if the declared pushid is not there but I need that push ID to work on other modules. I am still learning so I get easily confused with this kind of thing. Any help would be so much appreciated.
This is the line which is calling the table.
mToolsDatabase = FirebaseDatabase.getInstance().getReference().child("toolHistory");
mToolsDatabase.child(list_user_id).child(mCurrentUser.getUid()).addValueEventListener(new ValueEventListener(){
public void onDataChange(DataSnapshot dataSnapshot) {
final String toolName = dataSnapshot.child("name").getValue().toString();
final String toolUser = dataSnapshot.child("user").getValue().toString();
final String toolBorrow = dataSnapshot.child("dateTimeBorrowed").getValue().toString();
final String toolReturn = dataSnapshot.child("dateTimeReturn").getValue().toString();
final String toolStatus = dataSnapshot.child("status").getValue().toString();
final String toolId = dataSnapshot.child("logId").getValue().toString();
viewHolder.setName(toolName);
viewHolder.setUser(toolUser);
viewHolder.setDateTimeBorrowed(toolBorrow);
viewHolder.setDateTimeReturn(toolReturn);
viewHolder.setStatus(toolStatus);
viewHolder.setLogId(toolId);
}
Firebase has its inbuilt method FirebaseRecyclerAdapter for display items in RecyclerView
Also, you can follow this link for more info
https://grokonez.com/android/firebase-realtime-database-display-list-of-data-firebaserecycleradapter-android-development
This question already has answers here:
How to parse JSON in Java
(36 answers)
Closed 6 years ago.
I get a response but it's different for every user.
I want to extract the UserID & Name. How can I do this?
The response String:
{
"sessionkey":"f4b54dedlfkjhgdlfkjghdfslkjgh1a255242bf71597f4b35ac882f0702",
"user" : {
"userID" : "1",
"name":"Test"
}
}
I want to save 1 = (String userid)
and save Test = (String name)
Thanks in advance
This is just a simple JSON blob, so use a JSON Parser to extract the data.
My lib of choice is org.json.json.
String blob = "{ origin string }";
// create a new json object from the main blob
JSONObject root = new JSONObject(blob);
// extract the session key
String sessionKey = root.getString("sessionkey");
// extract the user object
JSONObject user = root.getJSONObject("user");
// extract the user id
String userId = user.getString("userID");
I am making QR code scan app. When i scan the QR Code for Email, I get the result i.e. given below,
String data = MATMSG:TO:abc#hotmail.com;SUB:email subject;BODY:email body;;
For getting code type i.e. MATMSG in string above i am doing this,
String[] parts = scanData.split(":");
qrCodeType = parts[0];
I want to make 3 strings from the data string like,
String to = abc#hotmail.com;
String subject = email subject;
String body = email body;
How can i use string functions to do this? Notice colons and semicolons in String data
Try the following:
String[] items = data.split(";");
String to = items[0].split(":")[2];
String subject = items[1].split(":")[1];
String body = items[2].split(":")[1];
Hope it helps
This question already has answers here:
How do I split a string in Java?
(39 answers)
Closed 8 years ago.
I have data with repeating pattern '###'.I want to extract all strings between this pattern.
The data is like -
son###can###e###nick###54###
how can i get all data between the pattern '###'.
try this:
String patternString = "###";
Pattern pattern = Pattern.compile(patternString);
String[] split = pattern.split(text);
You can use Scanner with "###" delimiter.
Scanner in = new Scanner("son###can###e###nick###54###");
in.useDelimiter("###");
while(in.hasNext)
String x = in.next();
//Do something with x;
x will hold everything between ###. You can easily store them in an Array inside the loop or use them anyway you like.
Try this:
String str = "son###can###e###nick###54###";
String newStr = str.replaceAll("[#]+", "");
or you can separate all world via
String rem = "###";
Pattern pattern = Pattern.compile(rem);
String[] splitarr = pattern.split(text);
for(int i=0;i<aplitarr.length();i++)
{
String word=aplitarr[i].ToString();
}
Hope this may help you!
try,
String[] separated = CurrentString.split("###");
separated[0]; // this will contain "son"
separated[1]; // this will contain "can"
or
StringTokenizer tokens = new StringTokenizer(CurrentString, "###");
String first = tokens.nextToken();// this will contain "son"
String second = tokens.nextToken();// this will contain "can"
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.