我正在使用的服务器返回一个json对象,该对象包含一个对象列表,而不仅仅是一个.
{
"1":{"id":"1","value":"something"},
"2":{"id":"2","value":"some other thing"}
}
Run Code Online (Sandbox Code Playgroud)
我想将此json对象转换为对象数组.
我知道我可以使用Gson,并创建一个这样的类:
public class Data {
int id;
String value;
}
Run Code Online (Sandbox Code Playgroud)
然后使用
Data data = new Gson().fromJson(response, Data.class);
Run Code Online (Sandbox Code Playgroud)
但它仅适用于json对象内的对象. 我不知道如何将带有数字的json对象转换为键.
或者我需要改变服务器以响应这样的事情?:
{["id":"1","value":"something"],["id":"2","value":"some other thing"]}
Run Code Online (Sandbox Code Playgroud)
但我不想更改为服务器,因为我必须更改所有客户端代码.
我已经在onCreate()方法中删除了标题.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
}
Run Code Online (Sandbox Code Playgroud)
标题不显示.但是在启动应用程序时仍会出现.
我可以使用
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
Run Code Online (Sandbox Code Playgroud)
或者说
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
Run Code Online (Sandbox Code Playgroud)
进入清单文件,因为我正在使用actionBar.如果我这样做,应用程序崩溃.
所以,我的问题是,有没有办法在应用程序启动时删除标题,因为我要在这里放一个闪屏.谢谢.
请注意:
谢谢你的回答,但我清楚地说我已经习惯actionBar.setDisplayShowTitleEnabled(false);
隐藏活动的标题栏.(如第一张图片所示)
但标题栏仍然出现在启动屏幕中(如第二张图所示).
和
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
Run Code Online (Sandbox Code Playgroud)
和
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
Run Code Online (Sandbox Code Playgroud)
会导致崩溃发射.这是在我使用动作栏后发生的.
当我使用angular.component()来创建angular 1.5提供的全新组件时,没有链接函数,因此注入ngModelController或任何其他控制器的旧方法不起作用.
require: 'ngModel',
link: function(scope, element, attrs, ctrls)
上面的代码用于访问ngModelController的指令.我们现在如何在组件中访问它?
在多线程程序中,我怀疑当一个线程在wait()时,它不会占用太多的cpu利用率,因此cpu可以交换来处理其他线程.
例如,100个线程一起启动相同的任务,而50个线程实际执行任务,而其他50个线程等待直到所有50个任务完成.后一种情况比前者花费的时间少得多.
任何人都可以建议一些关于此的读物吗?
我有一个可以自己运行的android项目.我想创建另一个扩展前项目的android项目.但是当库项目尝试创建一些使用findViewById(R.id.something)的组件时,它会抛出NoSuchFieldException.
这是库项目的代码:
/*
* Copyright 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY …
Run Code Online (Sandbox Code Playgroud) 这是我使用的代码:
//inserting a row at the bottom first
_numberOfRecords++;
[_tableView beginUpdates];
[_tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:_numberOfRecords-1 inSection:0]] withRowAnimation:UITableViewRowAnimationBottom];
[_tableView endUpdates];
//clear text
_inputField.text = @"";
//then scroll to bottom
CGPoint bottomOffset = CGPointMake(0, _tableView.contentSize.height + 44.0 + _tableView.contentInset.top - _tableView.bounds.size.height);
NSLog(@"%f", _tableView.contentSize.height + 44.0 + _tableView.contentInset.top - _tableView.bounds.size.height);
[_tableView setContentOffset:bottomOffset animated:YES];
Run Code Online (Sandbox Code Playgroud)
这将以非常奇怪的方式滚动tableview.但是如果我在插入之前插入滚动代码,它会正常工作,除非它忽略了最新插入的行.也就是说,它滚动到倒数第二行而不是滚动到最后一行(当然,因为它在插入新卷之前滚动.)
所以我相信这段代码没有问题,它应该滚动到的位置.问题可能来自行插入到tableview.它违反了滚动表格视图的动画.
我这样做是为了聊聊天.每次用户发送或接收消息时,我都会将包含该消息的行插入表视图,并将其滚动到底部.这就是我在这里使用tableView的原因.我尝试使用带有标签的scrollView,它工作正常,但tableView在聊天视图中似乎更受欢迎.
我在想使用scrollView或tableView,我发现Apple的内置消息应用程序正在使用tableView,所以我采用了tableView.如果带有Label的scrollView比tableView更好,请告诉我.
无论如何,如何在插入新行后将tableView滚动到底部?
在Jasmine中,你可以使用spyOn(object,'function').我试图窥探一个提供者,它被用作"提供者()".如何窥探呢?
提供者看起来像这样:
providers.provider('telecom', function() {
this.$get = function() {
return function() {
return 'something';
}
}
}
Run Code Online (Sandbox Code Playgroud)
在控制器中,它将像这样使用:
controllers.controller('ctrl', function(telecom) {
var isp = telecom();
});
Run Code Online (Sandbox Code Playgroud)
对于object.method(),我们可以spyOn(object,'method').那个provider()怎么样?
我用谷歌搜索,找不到任何有用的东西.我试过spyOn(提供者),但我得到错误说"undefined()方法不存在".
我甚至试图嘲笑提供者,但没有成功.(http://www.sitepoint.com/mocking-dependencies-angularjs-tests/)
android ×2
java ×2
angularjs ×1
findviewbyid ×1
gson ×1
ios ×1
jasmine ×1
json ×1
livechat ×1
spyon ×1
uiscrollview ×1
uitableview ×1