Reputation: 41
I'm trying to obtain a list of contacts from the native database with their Display Name and Phone Number and display each one in a check Box but it doesn't work with me
Here is the query I've been working on
LinearLayout ll;
CheckBox ch1;
String name;
String number;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main1);
Button save = (Button) findViewById(R.id.bSave);
Button retur = (Button) findViewById(R.id.bReturn);
retur.setOnClickListener(this);
ch1= (CheckBox)findViewById(R.id.checkBox1);
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI,null,null, null, null);
Cursor phones = cr.query(Phone.CONTENT_URI, null,null,null,null);
String number= phones.getString(phones.getColumnIndex(Phone.NUMBER));
String contactId =cursor.getString(cursor.
getColumnIndex(ContactsContract.Contacts._ID));
ch1.setText(contactId+" : "+number);
}
help
Upvotes: 0
Views: 298
Reputation: 4427
Make sure you're sending an actual string to your checkbox. I just tested it and YES you can setText on a checkbox. I dont know why thinksteep says you cant. try this:
ch1.setText(String.valueOf(contactId) + " : " + String.valueOf(number));
Upvotes: 1