一個問題工作一次(ID 1606993)這樣被張貼,但並沒有真正回答我的,所以這裏有雲:輸入僅在安卓
在爲Android,我創建,用戶必須輸入一個應用程序從應用程序鍵盤的數字繼續。當他們輸入完數字後,他們可以按回車鍵或主鍵。問題是,它只能工作一次。
這裏是我的聽力方法:
public boolean onKeyDown(int key, KeyEvent event)//Listens for key events
{
if(key==KeyEvent.KEYCODE_0)
add(0);
else if(key==KeyEvent.KEYCODE_1)
add(1);
else if(key==KeyEvent.KEYCODE_2)
add(2);
else if(key==KeyEvent.KEYCODE_3)
add(3);
else if(key==KeyEvent.KEYCODE_4)
add(4);
else if(key==KeyEvent.KEYCODE_5)
add(5);
else if(key==KeyEvent.KEYCODE_6)
add(6);
else if(key==KeyEvent.KEYCODE_7)
add(7);
else if(key==KeyEvent.KEYCODE_8)
add(8);
else if(key==KeyEvent.KEYCODE_9)
add(9);
else if(key==KeyEvent.KEYCODE_ENTER)
setNum();
else if(key==KeyEvent.KEYCODE_DPAD_CENTER)
setNum();
return true;
}
添加(INT麻木)方法添加NUM給佔用了屏幕,它不會引起任何問題的文本字段。
這裏是setNum():
protected void setNum()//Sets the number and tells the Runner it is set.
{
if(ray.size()==1)
num=ray.get(0);
else if(ray.size()==0)
num=0;
else
num=(ray.get(0)*10)+ray.get(1);
ray=new ArrayList<Integer>();//or ray.clear(), I've tried both
ready=true;
}
ArryayList射線是數被儲存在那裏。計算工作正常。 Int num是代碼使用的編號。布爾準備就緒,因爲在runner類中有一個while循環,等待準備好以繼續執行代碼。
while(!a.ready)
{
for(int x=0;x<100;x++);
}
任何想法?
編輯:這是在亞軍的方法被稱爲:
while(!go)
{
addText("It is White's move");
addText("Possible pieces to move");
for(int x=0;x<b.getWhite().getPiecesWithMoves(b).size();x++)//Loop to print White's pieces that can move
{
addText(""+(x+1)+") "+b.getWhite().getPiecesWithMoves(b).get(x));
}
got=false;
p=0;
while(!got)//Loop to enter number
{
addText("Input the number of the piece you want to move");
while(!a.ready)
{
for(int x=0;x<100;x++);
}
p=a.num-1;
if(p<b.getWhite().getPiecesWithMoves(b).size()&&p>=0)//Checks to make sure that p is valid
got=true;
a.num=0;
a.ready=false;
}
gl=b.getWhite().getPiecesWithMoves(b).get(p).getLocation();//Makes a location that is where the piece currently is
addText("Possible moves");
for(int x=0;x<b.getPiece(gl).getMoves(b).size();x++)//Loop to print where the piece can go
{
addText(""+(x+1)+") "+b.genL(b.getPiece(gl).getMoves(b).get(x)));
}
got=false;//reset
while(!got)//Loop to enter number
{
addText("Input the number of one of these moves.");
addText("If you wish to change, enter 0.");
while(!a.ready)
{
for(int x=0;x<100;x++);
}
p=a.num-1;
if(p==-1)
got=true;
else if(p<b.getPiece(gl).getMoves(b).size()&&p>=0)//Checks to make sure that p is valid
{
got=true;
go=true;
}
a.num=0;
a.ready=false;
}
}
gk=b.getPiece(gl).getMoves(b).get(p);//The location that the piece is going to
b.move(gk, b.getPiece(gl),gk.isTaken(),gk.isCastle());//Moves the piece
什麼是跑步者循環的重點?它不會只是作爲一個無限循環而存在嗎?或者它在異步線程中?處理類似事件的更好方法是使用廣播接收器 – 2011-04-27 18:16:33
什麼部分第二次不工作?錯誤?例外?錯號碼?沒有號碼?無限循環?惡魔? – Ishtar 2011-04-27 18:19:58
@John:我試着暫停它來等待來自主Activity的消息,但是它開始拋出異常中斷。 Runner類的確將消息發送給主類,如果這有幫助的話。 – Travis 2011-04-27 18:22:10