【发布时间】:2015-02-05 07:58:53
【问题描述】:
在我的 android 应用程序中,我有一个带有电话号码的 SQLite 数据库(这里我更改了其他不存在的号码以保护隐私)!
mySQLiteAdapter = new SQLiteAdapter(this);
mySQLiteAdapter.openToRead();
我创建了一个列表,其中包含数据库中的数字并打印在屏幕上以查看它是否有效,它会返回正确的数字!
List numeri = mySQLiteAdapter.getAllNumeri();
System.out.println("num tel: " + phone);
It give me back two numbers present in database --> [3401234567, 02123456]
然后我尝试将来电号码与此列表与此方法进行比较:
String phone = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
System.out.println("Incoming number - " + phone);
boolean retval = numeri.contains(phone);
if (retval == true) {
System.out.println("PHONE is contained in the list");
}
else {
System.out.println("PHONE is not contained in the list");
}
我尝试用我的号码 3401234567 拨打电话!
The println give me back: Incoming number: +393401234567
和
The condition give me back that "PHONE is not contained in the list!"
我也尝试通过添加国家前缀 (+39) 来更改数据库编号,但它不起作用!
谁能帮助我?谢谢
我认为它不是重复的,因为在其他问题中,比较两个字符串,这里我想将一个字符串与 arraylist 进行比较
【问题讨论】:
-
你做得对,你可以尝试调试我推荐的代码
-
您应该从您的数据库中选择号码,而不是选择全部然后进行列表搜索。例如,当你得到这个数字时,做一个选择语句,如果找到,则返回那个数字,否则它不会
-
@k0sh 你可以帮我这个例子吗???
标签: android string sqlite arraylist