在复选框中显示姓名和电话号码
我正在尝试从本机数据库获取联系人列表及其显示名称和电话号码,并将每个联系人显示在复选框中,但它对我不起作用
这是我一直在处理
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);
}
帮助的查询
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您将实际的字符串发送到复选框。我刚刚测试了它,是的,您可以在复选框上设置文本。我不知道为什么 thinksteep 说你不能。试试这个:
ch1.setText(String.valueOf(contactId) + " : " + String.valueOf(number));
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));
复选框仅代表两种状态(真/假)。您无法将文本设置为复选框。请参阅 复选框 的 Android 文档。您可能需要重新考虑您的策略。
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.