联系方式自动完成

时间:2012-12-10 05:02:04

标签: java android

第一篇文章。我是Android和编程的新手。我正在尝试的是从联系人列表中弹出一个自动完成文本框,其中包含自动完整名称。 IE,如果他们输入“john”,它会在他们的联系人中说“约翰史密斯”或任何约翰。代码是基本的,我从几个教程中提取它。

private void autoCompleteBox() {

        ContentResolver cr = getContentResolver();

        Uri contacts = Uri.parse("content://contacts/people");

        Cursor managedCursor1 = cr.query(contacts, null, null, null, null);

        if (managedCursor1.moveToFirst()) {

            String contactname;
            String cphoneNumber;

            int nameColumn = managedCursor1.getColumnIndex("name");
            int phoneColumn = managedCursor1.getColumnIndex("number");

            Log.d("int Name", Integer.toString(nameColumn));
            Log.d("int Number", Integer.toString(phoneColumn));

            do {
                // Get the field values
                contactname = managedCursor1.getString(nameColumn);
                cphoneNumber = managedCursor1.getString(phoneColumn);
                if ((contactname != " " || contactname != null)
                        && (cphoneNumber != " " || cphoneNumber != null)) {

                    c_Name.add(contactname);
                    c_Number.add(cphoneNumber);

                    Toast.makeText(this, contactname, Toast.LENGTH_SHORT)
                    .show();
                }

            } while (managedCursor1.moveToNext());

        }

        name_Val = (String[]) c_Name.toArray(new String[c_Name.size()]);
        phone_Val = (String[]) c_Number.toArray(new String[c_Name.size()]);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, name_Val);

        personName.setAdapter(adapter);

    }

personName是我的autocompletetextbox。因此,当我在模拟器(4.2)中使用手动输入的联系人通过人物应用程序时,它实际上有效,但是当我在我的设备上使用它时,它不会弹出任何名称。我确定这是荒谬的,但我试图找到答案,我无处可去。如果我不问,就无法学习。

这是日志

12-11 18:35:09.229:I / ActivityManager(578):显示 12-11 18:35:11.031:I / ActivityManager(578):从pid 4153开始u0 {cmp = com.fthatnoise.borrow.me / .AddItem}

12-11 18:35:11.161:D / dalvikvm(4153):GC_CONCURRENT释放&lt; 1K,2%free 9648K / 9784K,暂停5ms + 2ms,总共22ms 12-11 18:35:11.181:D / dalvikvm(4153):GC_FOR_ALLOC释放&lt; 1K,2%free 9648K / 9784K,暂停21ms,总计21ms 12-11 18:35:11.181:I / dalvikvm-heap(4153):将堆(frag case)增长到10.359MB,用于960016字节分配 12-11 18:35:11.201:D / dalvikvm(4153):GC_FOR_ALLOC释放0K,2%释放10585K / 10724K,暂停18ms,总计18ms 12-11 18:35:11.221:D / dalvikvm(4153):GC_CONCURRENT释放&lt; 1K,1%free 10637K / 10744K,暂停3ms + 1ms,总计15ms

12-11 18:35:11.551:I / ActivityManager(578):显示com.fthatnoise.borrow.me/.AddItem:+ 514ms 12-11 18:35:11.571:D / overlay(162):FROM_STATE = OV_BYPASS_3_LAYER TO_STATE = OV_CLOSED 12-11 18:35:11.911:D / overlay(162):FROM_STATE = OV_CLOSED TO_STATE = OV_BYPASS_3_LAYER 12-11 18:35:13.073:D / overlay(162):FROM_STATE = OV_BYPASS_3_LAYER TO_STATE = OV_CLOSED

0 个答案:

没有答案