从字符串,整数和浮点数构建字符串的最高效方法是什么?目前我正在这样做,它使用了大量的CPU时间.
String frame = this.frameTime + ":" +
this.player.vertices[0].x + "," +
this.player.vertices[0].y + "," +
this.player.activeAnimId + "," +
(int)this.player.virtualSpeed + "," +
this.map.getCurrentTime() +
(this.player.frameSound == -1 ? "" : "," + this.player.frameSound) +
(this.player.frameDecal.equals("") ? "" : "," + this.player.frameDecal) +
";";
Run Code Online (Sandbox Code Playgroud)
有没有办法更快地做到这一点?
我想使用mvc事件更改布局.我尝试过以下方法:
// $event instanceof \Zend\Mvc\MvcEvent
$serviceManager = $event->getApplication()->getServiceManager();
$controllerLoader = $serviceManager->get('ControllerLoader');
$controllerLoader->addInitializer(function ($controller) {
$controller->layout('layout/example');
// OR THIS
$controller->getEvent()->getViewModel()->setTemplate('layout/example');
});
Run Code Online (Sandbox Code Playgroud)
我的aproaches不会产生任何错误通知或其他东西.即使layout/example不存在也不行.为什么可以从控制器内部$this->layout()而不是从外部更改布局$controller->layout()?
我也这样试过:
// $event instanceof \Zend\Mvc\MvcEvent
$serviceManager = $event->getApplication()->getServiceManager();
$renderingStrategy = $serviceManager->get('DefaultRenderingStrategy');
$renderingStrategy->setLayoutTemplate('layout/example');
Run Code Online (Sandbox Code Playgroud)
这也不会丢失任何错误,但不会改变任何错误.
如何在运行时从控制器外部切换布局?
我遇到一个接收消息的线程处理程序的问题.我实现的所有其他线程这种模式工作正常.我的代码:
启动线程
InternalScoresThread t = new InternalScoresThread(
this.game.getApplicationContext(),
this.map.fileName, this.map.getCurrentTime(),
new Handler() {
@Override
public void handleMessage(Message msg) {
Log.d("DEBUG", "message received");
if (msg.getData().getBoolean("record")) {
Player.this.showtRecordMessage();
} else {
Player.this.showtFinishMessage();
}
Player.this.showTimeMessage();
Player.this.showRestartMessage();
}
});
t.start();
Run Code Online (Sandbox Code Playgroud)
线程类
public class InternalScoresThread extends Thread {
private Handler handler;
private String map;
private float time;
private Context context;
public InternalScoresThread(Context context, String map, float time, Handler handler) {
this.context = context;
this.handler = handler;
this.map = map;
this.time = time;
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 我有一个带有Float键和String值的Java HashMap.现在给出一个不在HashMap中的Float,我怎样才能找到与给定的Float最相似的键?
我正在尝试将 Material-UI 包装<ListItem button>到 react-router 中<NavLink>。基本上它工作正常,但我注意到<NavLink>Component 改变了<ListItem button>. 如果我以另一种方式包装它(ListItem 中的 NavLink),我将无法设置<ListItem>with样式,classes.linkActive因此这不是一个选项。
这是一个显示问题的最小代码示例:https : //codesandbox.io/s/xrxl90jv04
我一直在浏览这些组件,但我有点新的反应,所以关于如何防止 NavLink 更改颜色或以任何方式告诉 ListItem 再次使用默认/主题调色板的任何想法?
我在使用fusesource mqtt-client-java1.4-uber-1.0(在Android应用程序中)时遇到了一些问题.当我提供错误的IP或mqtt代理没有在正确的IP上运行时,它会警告消息"无法连接(回调)"但不能"无法连接(监听器)".当我提供正确的IP并且代理正在运行时,根本不会出现警报.我猜测听众根本不工作,不知何故,连接的成功回调并不明智.任何想法?下面是android活动的完整代码.
我正在使用这个版本的mqtt-client:mqtt-client-java1.4-uber-1.0.jar 我还尝试了不同的messe代理(服务器),它们是RSMB和Mosquitto
package racenet.mqtt;
import java.net.URISyntaxException;
import org.fusesource.hawtbuf.Buffer;
import org.fusesource.hawtbuf.UTF8Buffer;
import org.fusesource.mqtt.client.Callback;
import org.fusesource.mqtt.client.CallbackConnection;
import org.fusesource.mqtt.client.Listener;
import org.fusesource.mqtt.client.MQTT;
import racenet.mqtt.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
public class MQTTActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MQTT mqtt = new MQTT();
try {
mqtt.setHost("tcp://proper-ip-here:1883");
} catch (URISyntaxException e) {
new AlertDialog.Builder(MQTTActivity.this)
.setMessage("Could not set host")
.setNeutralButton("OK", null)
.show();
}
final CallbackConnection connection = mqtt.callbackConnection();
connection.listener(new Listener() {
public void onConnected() …Run Code Online (Sandbox Code Playgroud) 我的Android应用程序中的ExpandableListView有问题.我设置了自定义背景颜色,但滚动列表时颜色变为黑色,直到滚动停止.这是正常的还是可以更改"onScrollColor"?
我正在尝试为我的ZF2应用程序定义一些控制台路由,如http://packages.zendframework.com/docs/latest/manual/en/modules/zend.console.routes.html所述.
在模块配置我有:
'console' => array(
'router' => array(
'routes' => array(
'user-set-password' => array(
'options' => array(
'route' => 'user password <username> <password>',
'defaults' => array(
'controller' => 'User\Profile',
'action' => 'setpassword'
),
),
),
),
),
),
Run Code Online (Sandbox Code Playgroud)
但似乎永远不会匹配路线,因为它总是打印使用信息.还有像'test'这样的简单路线也不会匹配.(当我在路由参数中写入一些废话时,执行失败,Zend\Mvc\Router\Exception\InvalidArgumentException因此它在加载模块时识别控制台路由)
是我的错还是最新的zf2版本中的错误?
我面临着类似的问题,像这一个.我正在使用一些静态类成员在我的应用程序中包含单例.当我使用finish()离开主活动并再次启动时,所有静态成员仍然存在.调用Process.killProcess(Process.myPid())似乎不是一个好的解决方案; 当我离开应用程序时,我也不想取消设置所有静态成员,因为在扩展应用程序时这很容易出错.那么如何才能完全退出Android应用程序呢?
android ×4
java ×2
php ×2
console ×1
handler ×1
hashmap ×1
javascript ×1
layout ×1
material-ui ×1
mqtt ×1
quit ×1
react-router ×1
reactjs ×1
scroll ×1