Wael Ilahi
Wael Ilahi

Reputation: 41

Display Name and Phone Number(s) in check boxes

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

Answers (2)

bwoogie
bwoogie

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

kosa
kosa

Reputation: 66647

Check boxes represent only two states (true/false). You can't set text to check boxes. Refer android documentation for checkbox. You may need to reconsider your stratagey.

Upvotes: 0

Related Questions