我有一个编辑文本,在我的应用程序中用作搜索框.在我的Nexus 7上的Jelly Bean中,当我在正在监听的文本框中输入内容并点击时,输入KeyEvent = null并将ActionId = 0传递给onEditorAction()方法.有人遇到过这种情况么?我认为这可能是一个错误.
在下面的第二个if语句中,我得到一个空指针,因为actionId = 0和KeyEvent = null;
// Search field logic.
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.d(TAG, "onEditorAction");
if (event != null && event.getAction() != KeyEvent.ACTION_DOWN)
return false;
if (actionId == EditorInfo.IME_ACTION_SEARCH
|| event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
.....Do some stuff();
}
}
Run Code Online (Sandbox Code Playgroud) 我看过很多与此相关的帖子,但似乎没有一个问题我得到的相同.GetBusinessRulesTask扩展了AsyncTask.当我在单元测试用例中执行它时,onPostExecute()永远不会被调用.但是,如果我使用真实的客户端代码,则每次都会调用onPostExecute().不知道我在这里做错了什么.
测试用例:
package com.x.android.test.api;
import java.util.concurrent.CountDownLatch;
import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest;
import android.widget.Button;
import com.x.android.api.domain.businessrule.BusinessRules;
import com.x.android.api.exception.NetworkConnectionException;
import com.x.android.api.tasks.GetBusinessRulesTask;
import com.x.android.test.activity.SimpleActivity;
public class GetBusinessRulesTaskTest
extends
ActivityInstrumentationTestCase2<SimpleActivity> {
SimpleActivity mActivity;
Button mButton;
public GetBusinessRulesTaskTest() {
super("com.x.android.test.activity", SimpleActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
mActivity = this.getActivity();
mButton = (Button) mActivity
.findViewById(com.x.android.test.activity.R.id.b1);
}
public void testPreconditions() {
assertNotNull(mButton);
}
@UiThreadTest
public void testCallBack() throws Throwable {
final CountDownLatch signal = new CountDownLatch(1);
final GetBusinessRulesTask task = (GetBusinessRulesTask) new GetBusinessRulesTask(
new …
Run Code Online (Sandbox Code Playgroud) 我正在编写一个带有模型对象的应用程序,它将Restful接口暴露给某些Web服务.我注意到在Android中有一个java.net.URI和一个android.net.URI类.使用一个与另一个有什么好处?有没有其他人遇到这个并发现一个比另一个更好?
在下面的代码中,我将URI的各个部分解析为java.net URI对象,然后我可以调用httpGet(URI uri)
.但是,使用android.net类或只调用httpGet(String url)会有任何性能优势或任何好处吗?
public class RestMethods {
private String protocol;
private String host;
private Integer port;
private URI uri;
public String restGet(String path) throws MalformedURLException, InterruptedException, ExecutionException{
StringBuilder builder = new StringBuilder();
try {
// Execute HTTP Post Request
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(uri);
HttpResponse response = httpclient.execute(httpget);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
for (String line = null; (line = reader.readLine()) != null;) {
builder.append(line).append("\n");
}
} catch (ClientProtocolException …
Run Code Online (Sandbox Code Playgroud)