我在我的应用程序中使用AppCompat库(com.android.support:appcompat-v7:22.1.0).我在一个片段中创建了一个ActionBar.当我单击菜单项时,它会显示一个警告对话框.这是我的代码:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.action_new:
showFilterDialog();
return true;
case R.id.action_send:
new sendInventoryTask().execute();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Run Code Online (Sandbox Code Playgroud)
和我的showInventoryDialog方法:
private void showFilterInventoryDialog() {
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
LayoutInflater inflater= getActivity().getLayoutInflater();
View v = inflater.inflate(R.layout.dialog_filter_inventory,null);
alert.setView(v);
alert.setTitle(getResources().getString(R.string.filters));
alert.setPositiveButton(getResources().getString(R.string.filter), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// TODO
}
});
alert.setNegativeButton(getResources().getString(R.string.cancel), null);
alert.show();
}
Run Code Online (Sandbox Code Playgroud)
一切正常,但当我点击菜单项时,logcat显示错误:
I/AppCompatDelegate:Activity的LayoutInflater已安装了Factory,因此我们无法安装AppCompat的
怎么解决这个?
我是SSE的新手,我正在学习w3schools教程.我在他们的示例中添加了一些代码,以便我可以看到连接何时打开以及何时出现错误.这是我的代码:
<script>
var source = new EventSource("sse.php");
source.addEventListener('message', function(e) {
console.log("onmessage");
document.getElementById("result").innerHTML += event.data + "<br>";
}, false);
source.addEventListener('open', function(e) {
console.log("onopen");
}, false);
source.addEventListener('error', function(e) {
console.log('error '+e.readyState);
}, false);
</script>
Run Code Online (Sandbox Code Playgroud)
我的服务器端代码:
<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
$time = date('r');
echo "data: The server time is: {$time}\n\n";
flush();
?>
Run Code Online (Sandbox Code Playgroud)
文档说明了这一点
服务器发送的事件是指网页自动从服务器获取更新.之前也可以这样做,但网页必须询问是否有可用的更新.使用服务器发送的事件,更新会自动进行.
但控制台告诉我们相反的情况:
客户端请求新连接,获取消息,发生错误并关闭连接.每3秒重复一次.为什么会这样?
我正在尝试通过gradle将库添加到我的项目中.我收到一个错误:
错误:无法通知项目评估侦听器.
这是我的build.gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
compileOptions.encoding = 'ISO-8859-1'
defaultConfig {
applicationId "br.com.myapp"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
jcenter()
// The library owner indicates me to add the following lines
maven {
url 'http://clojars.org/repo'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.loopj.android:android-async-http:1.4.8'
compile 'com.github.machinarius:preferencefragment:0.1.1'
compile 'com.pavelsikun:material-seekbar-preference:0.8+'
compile …Run Code Online (Sandbox Code Playgroud) 我正在使用 Java 在主 zip(名称 finalZip.zip)中创建一些 zip 文件,这些文件名包含 áóç 等字符。当我尝试创建一个 zip 文件时,文件名是错误的。例如,当 3-ORDINÁRIA-2017-05-03.zip 时,它会出现 3-ORDIN+üRIA-2017-05-03.zip
String zipName= number + "- ORDINÁRIA -" + sdf.format(sdfComplete.parse(date.getTime()) + ".zip";
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(bos);
try {
bos = createZipFile(); // populate each zipFile with some images
// generating zip file, ex: 6-ORDINÁRIA-2017-03-15.zip
zipFinal.putNextEntry(new ZipEntry(zipName));
zipFinal.write(bos.toByteArray());
zipFinal.closeEntry();
}
...
Run Code Online (Sandbox Code Playgroud)
我想要带有 UTF-8 字符集的 zip 文件。我该如何解决这个字符集问题?