On Android, I try to retrieve some specific fields form a contact but I cant find how to do it.
I'd like to retrieve the following fields: "Enterprise", "Function", and "Label" and of course the fields "Name", "First Name" and "Phone number(s)"
The fields are here on a contact (numbered 1,2 and 3 on the screenshots):
Screen 1
Screen 2
Is there some sample functions already available ????
Just to know how to get those fields. I'm not a java expert...
I think you should use a Model with getter and setter methods. Than you can access all the fields with calling getter method.
Note: You have to save your data first.
Demo:
public class Person {
private String name; // private = restricted access
// Getter
public String getName() {
return name;
}
// Setter
public void setName(String newName) {
this.name = newName;
}
}
Related
I'm writing Android app with Room Database. My database contains GroupVc entity with such code:
#Entity
public class GroupVc {
#ColumnInfo(name = "language")
private String language;
#NonNull
#PrimaryKey
#ColumnInfo(name = "name_group")
private String nameGroup;
public GroupVc(String language, String nameGroup) {
this.language = language;
this.nameGroup = nameGroup;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
#NonNull
public String getNameGroup() {
return nameGroup;
}
#NonNull
public void setNameGroup(String nameGroup) {
this.nameGroup = nameGroup;
}
}
As you can see my entity class contains two columns where nameGroup is my PrimaryKey. In my application I want to let the user to see the full list of groups and change the name of Group DialogFragments by entering new Group's names. To implement such function I've created the next DAO #Query method:
#Dao
public interface GroupVcDao {
#Query("UPDATE groupvc SET name_group= :newName WHERE name_group= :currentName")
void updateNameOfGroup(String currentName, String newName);
}
In this QUERY I want to change name of GroupVc by getting the existing name of GroupVc from RecyclerView (currentName param) and applying new one from DialogFragment (newName param).
My problem is that this QUERY doesn't bring any effect and doesn't update the name. Although I don't get any errors or exceptions. So I need to know: does such QUERY correct? Is it possible to write Update queries where primary key is changeable value and condition at the same time?
Here is the link to my complete project on GitHub
https://github.com/LAHomieJob/VocaNote
I can't be sure, but my guess would be that your query is working, but since you're changing the primary key your database is left with an instance of the old object as well as the new one. Try checking to see if you have an object with both the old name_group and the new name_group. Also if you're looking to allow your users to change the group name, it may make sense to move your primary key to a UUID or some other key that doesn't change.
I have one field called "Serial Number" in firebase database, i want to show its value to android application. I have user #PropertyName annotation to access it through model class.
#PropertyName("Serial Number")
private String serialNumber;
But it is not working, if i remove space from firebase database as well as from model class, it works fine. But how to do it with space in field name?
Along with declaring variable name as #PropertyName, you need to add #PropertyName for getter and setter as below:
#PropertyName("Serial Number")
private String serialNumber;
#PropertyName("Serial Number")
public String getSerialNumber() {
return serialNumber;
}
#PropertyName("Serial Number")
public void setSerialNumber(String serialNumber) {
this.serialNumber = serialNumber;
}
I am using the .Net backend for Azure Mobile Service. I can successfully run the following query, and it returns all items from the database however it only returns the items with their IDs and no other columns are returns, they are all set to null
TableName.execute(new TableQueryCallback<ClassName>() {
#Override
public void onCompleted(List<ClassName> result, int count,
Exception exception, ServiceFilterResponse response)
So do I need to supply a select filter or should I be using the TableOperationsCallback? There is no error, it just returns all the columns as null except for the id column
Thanks
Make sure that the casing of the fields match between the client and the server. By default the .NET backend will make all properties camel-case, so that if you have this class:
public class Person : EntityData
{
public string Name { get; set; }
public int Age { get; set; }
}
Then the JSON response in a GET operation will look something like this:
[
{ "id":"the-first-id", "name":"John Doe", "age":33 },
{ "id":"the-first-id", "name":"Jane Roe", "age":34 }
]
So you need to define in your Android application a type where the field is either named in lower case, or properly tagged with the #SerializeName annotation, like in the example below (you don't need to do that for the id property as it's special-cased by the SDK):
public class Person {
#SerializedName("id")
public String Id;
#SerializedName("name")
public String Name;
#SerializedName("age")
public String Age;
}
I am using eclipse to create a app engine based application where I am also using app engine datastore(using JPA) using endpoints.
I wrote a test application with help from
https://developers.google.com/eclipse/docs/endpoints-addentities
and it went fine.
Now I want to create an entity where I define my own Key rather than it being automatically assigned by the system. Can someone help me as to what do I need to do that in my Notes.java entity class. By default the Notes.java like this.
package com.bfp.mypackage;
import javax.persistence.Entity;
import javax.persistence.Id;
#Entity
public class Note {
#Id
private String id;
private String emailAddress;
private String description;
public Note() {
}
public String getId() {
return id;
}
public String getDescription() {
return description;
}
public String getEmailAddress() {
return emailAddress;
}
public void setId(String idIn) {
this.id = idIn;
}
public void setDescription(String description) {
this.description = description;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
}
When I test this code I see the Note entity created in my dev app server admin console with the values(an emailAddress, a dsescription and an ID(I pass timestamp there)) I had supplied. I see two other fields created when I view the entity in admin console. One "Key" and other "Write ops". Now the "Key" field as I understand is the one generated automatically by java. Is there anyway I can set my emailAddress field as the Key? If so then what changes I need to do in above code. That way I can use emailAddress as the unique key for each entity.
You must set your email address as the "Key" name : a key is defined by either an auto-incremented long ID, or a user assigned key name that is unique for an entity kind.
I'm not the most experimented using JPA since I've used mostly JDO and the low level approach, but you might have to use directly the com.google.appengine.api.datastore.Key object instead of a java.lang.String attribute...
The low level API method is :
KeyFactory.createKey("EntityName", "whatever#domain.com");
I have a ListView, actually generated by parsing a XML file downloaded from Internet.
This XML file contains data about a person: IdNumber, Name, Age, PhotoURL, Birthday, Phone numbers, Email account, etc.
I get all the XML data when generating the ListView, but on each row I show some values of the person (not all), just name, age, photo (from the PhotoURL) and email.
I would like to get the "IdNumber" to parse it to the Activity that shows all the info, this activity should read the "IdNumber", get all the data of only that person and show it.
How can I parse a value that I'm not using on my ListView?
Thanks in advance,
Herni
For each row in the listView create an Object with all the fields you've originally parsed.
You will create a model that like this:
public class Person
{
String idNumber,Name,Email;
public void SetIdNumber(String p_value)
{
this.idNumber = p_value;
}
public void SetName(String p_value)
{
this.Name= p_value;
}
public void SetEmail(String p_value)
{
this.Email= p_value;
}
//Get Methods
public String GetIdNumber()
{
return idNumber;
}
public String GetName()
{
return Name;
}
public String GetEmail()
{
return Email;
}
When you parse your xml you will create an ArrayList list; and fill after the 'list' you will use this everywhere you want.
For example when you click your first item of your listview you could ;
Person p = list.get(position that clicked your listview);
Now you will use your Person model. This is simple object oriant man.