我正在学习如何取消asyncTask,因此下面的代码没有用处.
我试图调用asyncTask并执行它然后取消它并执行它.
MyAsyncTask asyncTask = new MyAsyncTask();
Log.i("cancel","cancel 1");
asyncTask.execute();
Log.i("cancel","cancel 2");
asyncTask.onCancelled();
Log.i("cancel","cancel 3");
asyncTask.execute();
Log.i("cancel","cancel done");
Run Code Online (Sandbox Code Playgroud)
"取消1"和"取消2"在logcat上显示正确执行,但当"取消3"试图执行时抛出ActivityThread.performLaunchActivity错误.(在logcat上没有显示取消3)我的asyncTask代码有什么问题吗?
private class MyAsyncTask extends AsyncTask<String,Integer,Void>{
private ArrayList<Map<String, String>> list;
private ProgressBar progressBar;
@Override
protected Void doInBackground(String... arg0) {
progressBar = (ProgressBar)findViewById(R.id.year_expense_progressbar);
progressBar.setVisibility(View.VISIBLE);
getListView().setVisibility(View.GONE);
textView.setVisibility(View.GONE);
list = new ArrayList<Map<String, String>>();
String time = "";
String category = "";
String expense = "";
String day = "";
String month = "";
totalExpense = 0;
Cursor c = SQLLiteAdapter.fetchAllItems();
while(c.moveToNext() != false){
if(isCancelled()){
Log.e("cancel","cancel …Run Code Online (Sandbox Code Playgroud) 一个非常简单的问题.为什么在第一个while循环中跳过scanf.我已经尝试使用getchar(),结果是一样的.getchar被跳过了.
如果你们不明白我在说什么,你可以尝试编译它,你们会理解我在问什么.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct rec{
int num;
char pref[16];
float point;
struct rec* next;
}rec;
void dataInput(float*,char*);
rec* insertNode(rec*);
int main(){
int i=1;
rec* entr,*pt = NULL;
entr = (rec*) malloc(sizeof(rec));
entr->num = i;
dataInput(&entr->point,entr->pref);
entr->next = NULL;
char key;
i++;
while(1){
printf("Continue ? If YES press 'y',or NO press 'n'\n");
key = getchar();
if(key == 'n')break;
else if(key == 'y'){
if(!pt){
pt = insertNode(entr);
}else{
pt = insertNode(pt);
}
dataInput(&pt->point,pt->pref);
pt->num = i; …Run Code Online (Sandbox Code Playgroud) 我正在开发Java Swing应用程序.
当我退出应用程序时,会弹出optionDialog,它会询问我是否要在退出之前保存文件.
我想要做的是optionDialog上有三个按钮(YES,NO,CANCEL)我想让optionDialog通过箭头键而不是tab键来改变按钮的焦点.如何在optionDialog中为按钮创建关键监听器?
到目前为止,这是我的代码
Object[] options = {" YES "," NO ","CANCEL"};
int n = JOptionPane.showOptionDialog(Swing4.this,
"File haven't save yet." +
" \n Are you want to save the file?",
"Confirm Dialog",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE,
null, //do not use a custom Icon
options, //the titles of buttons
options[1]); //default button title
if(n == JOptionPane.YES_OPTION){
if(helper.updateFile("text.txt", gatherAllContent(), Swing4.this)){
System.exit(0);
}
label.setText("There is something wrong on quit");
}else if(n == JOptionPane.NO_OPTION){
System.exit(0);
}else if(n == JOptionPane.CANCEL_OPTION){
System.out.println("Cancel");
}
Run Code Online (Sandbox Code Playgroud) 我想用从ajax收到的数据更改icon1和icon2的位置.
"结果"是div元素.通过显示从ajax收到的消息它工作正常,但我想知道为什么"icon1"和"icon2"没有移动.收到消息并且"result"元素每0.5秒更改一次并显示结果.奇怪的?!
我尝试在chrome上使用代码,但它不起作用.我该怎么做我的代码.我没有在其他浏览器上试过,如果Chrome旁边的浏览器有效,请告诉我.谢谢.
setInterval(function(){
// post data
$.ajax({
type: "POST",
url: "http://localhost:8080",
data: {id:mId,color:mColor,x:mX,y:mY}
}).done(function(msg){
// result is div element
result.text(JSON.stringify(msg) );
}).fail(function(jqXHR, textStatus) {
result.text( "Request failed: " + textStatus );
});
var jObj = jQuery.parseJSON( result.text() );
// icon1 and icon2 is div element
icon1.css({
position:"absolute",top:(jObj[0].y),left:(jObj[0].x)
});
icon2.css({
position:"absolute",top:(jObj[1].y),left:(jObj[1].x)
});
}, 500);
Run Code Online (Sandbox Code Playgroud)