我在Android源代码中看到了一个不熟悉的符号: *=
例如: density *= invertedRatio;
我不熟悉星等号表示法.有人可以解释一下吗?
我试图获取以下代码片段的正确Big-O:
s = 0
for x in seq:
for y in seq:
s += x*y
for z in seq:
for w in seq:
s += x-w
Run Code Online (Sandbox Code Playgroud)
根据我从(Python算法)得到这个例子的书,他们解释如下:
z循环运行一系列线性迭代,并且它包含一个线性循环,因此总复杂度为二次方或Θ(n 2).y环显然是Θ(n).这意味着x循环内的代码块是Θ(n + n 2).整个块执行x循环的每一轮,运行n次.我们使用乘法规则得到Θ(n(n + n 2))=Θ(n 2 + n 3)=Θ(n 3),即立方.
我不明白的是:O(n(n + n 2))怎么会变成O(n 3)?数学是否正确?
我试图在我的代码中检测7"平板电脑(即Kindle Fire和Nook Color).但是,仅测试1024x600的最小尺寸并不好,因为那时Galaxy Nexus也会通过这个测试.任何人都有检测这个的经验那种信息?
谢谢,伊戈尔
编辑: 我找到了一种方法来检测Kindle Fire和Nook Color设备,代码如下:
Activity activity = (Activity) activityContext;
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = activity.getWindowManager().getDefaultDisplay().getWidth();
int height = activity.getWindowManager().getDefaultDisplay().getHeight();
if ((width == 1024 && height == 600) || (width == 600 && height == 1024)) {
//Detects 7" tablets: i.e. Kindle Fire & Nook Color
isTablet = true;
}
Run Code Online (Sandbox Code Playgroud) 我有一项上传文件的特殊服务。上传完成后,我从服务发送了一个广播-包含一个特殊的序列化对象。该对象可能是许多类的实例。为了识别此对象类,我使用了自定义的意图类型。
外观:
// Sending broadcast
Intent intent = new Intent(UploaderService.ACTION_UPLOAD_SUCCESSFULLY);
intent.setType(UploaderService.TYPE_DOC);
intent.putExtra(UploaderService.FIELD_RESULT, object);
context.sendBroadcast(intent);
// Registering receiver
IntentFilter filter = new IntentFilter(UploaderService.ACTION_UPLOAD_SUCCESSFULLY);
filter.addDataType(UploaderService.TYPE_DOC);
registerReceiver(receiver, filter);
Run Code Online (Sandbox Code Playgroud)
在注册接收方时,我抓住了IntentFilter.MalformedMimeTypeException
。
TYPE_DOC
不变的样子"vnd.com.my.package.doc"
。
因此,我想,我的mime类型必须在系统中注册。我如何在代码中做到这一点?
我从https://www.python.org/downloads/release/python-351/运行了Python 3.5.1安装程序.但是,在命令行中,当我去运行时pip
,我看到一个错误:'pip' is not recognized as an internal or external command
.
有什么不对?
我对批注处理器的当前理解是,它指的是预先准备文件以查找某些批注的代码,然后基于该代码生成或更改其他代码。它发生在项目的常规编译阶段之前。
在gradle中,我们通常使用apt,kpt-我有时看到使用annotationProcessor
-表示在“注释处理时”需要一些依赖。
如果上面的理解是正确的,那么compileOnly
与apt,kpt等有什么不同?
我在Java中有这个代码:
mViewModel.getSetupData().observe(this, this::updateTime);
Run Code Online (Sandbox Code Playgroud)
的注册方法接受一个参数。将此代码转换为 Kotlin 时,以下内容不起作用:
mViewModel?.getSetupData()?.observe(this, ::updateTime)
Run Code Online (Sandbox Code Playgroud)
IDE (android studio) 抱怨
类型不匹配。要求:观察者。找到 KFunction1。
有什么线索吗?
java-8 kotlin android-studio method-reference android-livedata
我有一个crontab条目,应该像这样执行node.js脚本:
*/5 * * * * node /home/campaigns/reporting/UNIT_TESTS/testCron.js > /home/campaigns/reporting/UNIT_TESTS/cron.log
但是,它不会执行,并且不会更新日志文件.当我手动运行脚本时,一切正常.有任何想法吗??
谢谢你,伊戈尔
我有一个这样的options_menu.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/search"
android:title="@string/search_title"
android:icon="@drawable/ic_search"
android:showAsAction="collapseActionView|ifRoom"
android:actionViewClass="android.widget.SearchView" />
</menu>
Run Code Online (Sandbox Code Playgroud)
当我做一个项目 - >清理或构建时,我收到一个错误:
不允许使用字符串类型(在'showAsAction'中使用值'collapseActionView | ifRoom')
我无法弄清楚出了什么问题.我的目标SDK版本是11.有人知道是什么导致了这个吗?
谢谢,伊戈尔
在我的应用程序中,我收到用户插入的URL.该URL可以是 - 例如 - xx.sd
.使用任何Web浏览器,此URL都是有效的URL,但是当尝试按意图打开它时,会发生崩溃:android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=xx.sd }
.
我使用此检查此URL是有效的URL
Patterns.WEB_URL.matcher(model.getTarget().getUrl()).matches()
Run Code Online (Sandbox Code Playgroud)
并使用此代码打开意图
Intent i = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(model.getTarget().getUrl()));
itemView.getContext().startActivity(i);
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过追加http
或https
在URL之前解决此问题(如果不存在)但是如果我的URL以其他协议ftp
或file
其他协议开头.任何人都可以帮我解决这个问题.
我有一个11 Fragment
中viewPager
,当tablayout
要显示这11名片段,他们的文本无法正确显示.
这是我的问题的截图:
这是我的activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/xmlDrawerLayoutRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activities.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v7.widget.Toolbar
android:id="@+id/xmlToolbarMain"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<!-- navigation opener -->
<ImageButton
android:id="@+id/btnHomeToolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="?attr/colorPrimary"
android:paddingRight="10dp"
android:clickable="true"
android:src="@drawable/menu"/>
<!-- app name -->
<TextView
android:id="@+id/txttitleToolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title"
android:layout_gravity="right"
android:textColor="#ffffff"
android:textSize="16sp"
android:paddingRight="10dp"/>
<!-- search box-->
<ImageButton
android:id="@+id/btnSearchToolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:paddingLeft="10dp"
android:clickable="true"
android:src="@drawable/search"
android:background="?attr/colorPrimary"/>
</android.support.v7.widget.Toolbar>
<!-- Tablayout -->
<android.support.design.widget.TabLayout
android:id="@+id/xmlTabLayoutMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/xmlToolbarMain"
android:background="?attr/colorPrimary" …
Run Code Online (Sandbox Code Playgroud)