刚开始使用Kotlin并且我已经阅读了官方文档,我在kotlin库中实现接口时遇到了问题.
这是java中的接口:
public interface ResultCallBack {
void detailsRetrieved(Obj var1, AnotherInterface var2);
void anotherDataRetrieved(int var1, AnotherInterface var2);
}
Run Code Online (Sandbox Code Playgroud)
我从kotlin调用的方法是这样的:
public static void startLibActivity(Context context, ResultCallBack callback) {
sLuhnCallback = callback;
context.startActivity(new Intent(context, Library.class));
}
Run Code Online (Sandbox Code Playgroud)
我如何调用startLibActivity从科特林和实施ResultCallBack,以及
我想我坚持这个试验:
Library.startLibActivity(activity, {})
我已经尝试了很多可能性{},仍然存在正确实现的问题.
试图使用声明:
SELECT *
FROM data.example
WHERE TIMESTAMP(timeCollected) < DATE_ADD(USEC_TO_TIMESTAMP(NOW()), 60, 'MINUTE')
Run Code Online (Sandbox Code Playgroud)
从我的bigquery数据中获取数据.即使时间不在范围内,它似乎也返回相同的结果集.timeCollected是格式2015-10-29 16:05:06.
我正在尝试构建一个旨在返回的查询是不超过一小时的数据.因此,应该返回最后一小时内收集的数据,其余的应该被忽略.
我正在尝试通过帐户类型从原始联系人中检索电话号码.使用下面的代码段,
String SELECTION =
ContactsContract.RawContacts.ACCOUNT_TYPE + "='" + Constants.ACCOUNT_TYPE + "'";
ContentResolver cr = this.getContentResolver();
Cursor cur = cr.query(ContactsContract.RawContacts.CONTENT_URI,
null, SELECTION, null, ContactsContract.Contacts.DISPLAY_NAME + " ASC");
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String type = cur.getString(cur.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_TYPE));
String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
//String phone = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Log.e("number",name);
// hasPhoneNumber(cur.getString(cur.getColumnIndex(ContactsContract.RawContacts._ID)));
}
cur.close();
}
Run Code Online (Sandbox Code Playgroud)
我可以检索绑定到帐户类型的所有联系人,但是,hasPhoneNumber(String contactId)返回一个空光标.
private boolean hasPhoneNumber(String id) {
Cursor pCur = this.getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
new String[]{id}, null);
while (pCur.moveToNext()) {
String phoneNo = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); …Run Code Online (Sandbox Code Playgroud) 使用下面的代码,我能够使用 Nanohttpd 轻量级服务器在 android 手机上创建一个移动服务器。该代码基本上遍历主机 android 设备的根目录,并将文件和文件夹列为链接。我想要实现的是,当用户单击任何链接(文件夹链接)时,浏览器应显示单击的文件夹链接中包含的文件和文件夹。我该怎么做,因为我找不到任何适合初学者的 Nanohttpd 文档。
import java.io.File;
import java.util.Map;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.widget.TextView;
public class MainActivity extends Activity {
private static final int PORT = 8080;
private TextView hello;
private WebServer server;
private Handler handler = new Handler();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
hello = (TextView) findViewById(R.id.hello);
}
/*
* There are some earlier versions of android that can not implement this
* method of …Run Code Online (Sandbox Code Playgroud) 我有一个可能的事件样本列表:
incident = [
"road", "free", "block", "bumper", "accident","robbery","collapse","fire","police","flood"]
Run Code Online (Sandbox Code Playgroud)
我想检查句子中是否有任何这样的单词.
例如."这座建筑着火了"
这应该返回true,因为列表中有fire并且返回false,否则返回false.
我尝试用这种方法做到这一点:
query = "@user1 @handler2 the building is on fire"
if any(query in s for s in incidentList):
print("yes")
else:
print("no")
Run Code Online (Sandbox Code Playgroud)
但它总是失败,因为它反对何时query = "fire".
编辑
并且在事件包含元素的情况下说:"街头斗争",我希望它返回true,假设查询包含街道或战斗.我该如何解决?