2017-04-09 43 views
0

我是新的android開發,我將某個應用儲物櫃,但是當我按下屏幕上的按鈕,我爲創建鎖定屏幕,我的EditText字段中的顯示僅給出與該按鈕相關的一個數字,並且不會再添加到該行。它只是覆蓋以前按下的按鈕文字。這是迄今爲止我所做的代碼:我不能在我的EditText領域獲得多個號碼時,請按屏幕上的按鈕,我創建

public class ScreenLock extends AppCompatActivity { 
Button b0; 
Button b1; 
Button b2; 
Button b3; 
Button b4; 
Button b5; 
Button b6; 
Button b7; 
Button b8; 
Button b9; 
Button bok; 
Button bcancel; 
EditText passdisp; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_screen_lock); 
    b0= (Button) findViewById(R.id.button0); 
    b1= (Button) findViewById(R.id.button1); 
    b2= (Button) findViewById(R.id.button2); 
    b3= (Button) findViewById(R.id.button3); 
    b4= (Button) findViewById(R.id.button4); 
    b5= (Button) findViewById(R.id.button5); 
    b6= (Button) findViewById(R.id.button6); 
    b7= (Button) findViewById(R.id.button7); 
    b8= (Button) findViewById(R.id.button8); 
    b9= (Button) findViewById(R.id.button9); 
    bok= (Button) findViewById(R.id.buttonok); 
    bcancel= (Button) findViewById(R.id.buttoncancel); 
    passdisp= (EditText) findViewById(R.id.passDisplay); 
} 


public void buttonpress0(View view){ 
    passdisp.setText(b0.getText()); 
} 
public void buttonpress1(View view){ 
    passdisp.setText(b1.getText()); 
} 
public void buttonpress2(View view){ 
    passdisp.setText(b2.getText()); 
} 
public void buttonpress3(View view) { passdisp.setText(b3.getText()); } 
public void buttonpress4(View view){ 
    passdisp.setText(b4.getText()); 
} 
public void buttonpress5(View view){ 
    passdisp.setText(b5.getText()); 
} 
public void buttonpress6(View view){ 
    passdisp.setText(b6.getText()); 
} 
public void buttonpress7(View view){ 
    passdisp.setText(b7.getText()); 
} 
public void buttonpress8(View view){ 
    passdisp.setText(b8.getText()); 
} 
public void buttonpress9(View view){ 
    passdisp.setText(b9.getText()); 
} 

} 我知道這是不是有效的編碼,但它是我的第一稿,我真的很感激任何幫助解決問題

回答

2

這是因爲你保持設置文本,而必須使用添加.append()

這樣的解決方案是文本

更換passdisp.setText(b5.getText());

passdisp.append(b5.getText());

所有按鈕的onClick方法

+0

太感謝你了,它的工作很大 – Rayomand

相關問題