ebi leong

Greenhorn
+ Follow
since Jun 27, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by ebi leong

Sorry about that mistake of not using the code tag. Resend: I am doing a android project on retrieve contacts and i have code out on retrieving contacts from the android phone, but currently i want to implement it to just retrieve ONLY "Mobile" TYPE numbers and i would like to seek help on my issue and hope someone can guide me to show some examples.

This is my following Activity code:



And this is my android Custom Adapter:

11 years ago
Hi there, I am doing a android project on retrieve contacts and i have code out on retrieving contacts from the android phone, but currently i want to implement it to just retrieve ONLY "Mobile" TYPE numbers and i would like to seek help on my issue and hope someone can guide me to show some examples.

This is my following Activity code:

String contactNumber = null;
String nameOfContact = null;
private ListView lv;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

ArrayList<ContactsBean> pc1 = getContactNumbers(this);
ArrayAdapter<ContactsBean> adapter = new ContactAdapter(this, R.layout.contactlistitem, pc1);

lv = (ListView)findViewById(R.id.contactList);

lv.setAdapter(adapter);

}

public ArrayList<ContactsBean> getContactNumbers(Context context){
String contactNumber = null;
ArrayList<ContactsBean> phoneContacts = new ArrayList<ContactsBean>();
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
String nameOfContact = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null);
while (pCur.moveToNext()) {
// Do something with phones
contactNumber = pCur.getString(pCur.getColumnIndex(Phone.NUMBER));
phoneContacts.add(new ContactsBean(nameOfContact, contactNumber));
}
pCur.close();
}
}
}
cur.close();
return phoneContacts;
}

And this is my android Custom Adapter:

public class ContactAdapter extends ArrayAdapter<ContactsBean>{
private Context context;
private int layoutResourceId;
private List<ContactsBean> contactList;

public ContactAdapter(Context context, int layoutResourceId, List<ContactsBean> contactList){
super(context,layoutResourceId,contactList);
this.context = context;
this.layoutResourceId = layoutResourceId;
this.contactList = contactList;
}

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View view = convertView;

if(view == null)
{
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
view = inflater.inflate(layoutResourceId, parent, false);
ContactHolder contactHolder = new ContactHolder();
contactHolder.txtName = (TextView)view.findViewById(R.id.txtDisplayName);
contactHolder.txtPhone = (TextView)view.findViewById(R.id.txtPhoneNo);
contactHolder.setContact(contactList.get(position));
view.setTag(contactHolder);
}

return view;
}

static class ContactHolder{
TextView txtName;
TextView txtPhone;
ContactsBean contactList;

protected void setContact(ContactsBean contact)
{
txtName.setText(contact.getNameOfContact());
txtPhone.setText(contact.getContactNumber());
contactList = contact;
}

protected ContactsBean getContact() {
return contactList;
}
}

@Override
public ContactsBean getItem(int position)
{
return contactList.get(position);
}

}
11 years ago
Oh okay..
Erm so how do I create a servlet for my android project because i need to make a communication between the android and mySql database. And i search some tutorial on creating the servlet in android but i couldn't understand how to create an servlet for android in eclipse. So I'm trying to seek for help on this problem, as i heard it does similar coding as doing JSP servlet.

Best regards
11 years ago
Hi there!

I working out an android application that has a function of like VOIP and messaging type function between two different android phone. Each user register an account to the app to use the features. And I have a problem on creating a servlet in eclipse, when i right-click "New...Servlet" on my android project, i couldn't create it because it is an android project folder so I would like to ask for help on my problem on how to create the servlet in android project.

Best Regards!

11 years ago