2014-01-21 86 views
0

我有我創建了一個數字鍵盤,它正在進入文成的EditText框,我有工作,但不知道如何代碼刪除按鈕。我需要它一次刪除一個字符。Android使用自定義數字鍵盤,如何創建刪除鍵?

下面是一個代碼示例:

public class QOQuickOrder extends Activity implements OnClickListener { 

private final String MY_DATABASE_NAME = "/sdcard/hdw"; 

private EditText qoItemNumber; 
private EditText qoOrderQty; 
private TextView qoItemDesc; 

Cursor c; 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.qo_quickorder_layout); 

    qoItemNumber = (EditText) findViewById(R.id.etqoItemNumEntry); 
    qoOrderQty = (EditText) findViewById(R.id.etqoItemQtyEntry); 
    qoItemDesc = (TextView) findViewById(R.id.tvqoItemDesc); 

    qoItemNumber.selectAll(); 
    qoItemNumber.setText(""); 

    Button oneButton = (Button) findViewById(R.id.btn1); 
    Button twoButton = (Button) findViewById(R.id.button2); 
    Button threeButton = (Button) findViewById(R.id.button3); 
    Button fourButton = (Button) findViewById(R.id.button4); 
    Button fiveButton = (Button) findViewById(R.id.button5); 
    Button sixButton = (Button) findViewById(R.id.button6); 
    Button sevenButton = (Button) findViewById(R.id.button7); 
    Button eightButton = (Button) findViewById(R.id.button8); 
    Button nineButton = (Button) findViewById(R.id.button9); 
    Button zeroButton = (Button) findViewById(R.id.button0); 

    oneButton.setOnClickListener(this); 
    twoButton.setOnClickListener(this); 
    threeButton.setOnClickListener(this); 
    fourButton.setOnClickListener(this); 
    fiveButton.setOnClickListener(this); 
    sixButton.setOnClickListener(this); 
    sevenButton.setOnClickListener(this); 
    eightButton.setOnClickListener(this); 
    nineButton.setOnClickListener(this); 
    zeroButton.setOnClickListener(this); 

    qoItemNumber.setOnFocusChangeListener(new View.OnFocusChangeListener() { 

     @Override 
     public void onFocusChange(View v, boolean hasFocus) { 
      // TODO Auto-generated method stub 
      if (hasFocus = true){ 

       getItemDesc(); 
      } 

     } 
    }); 

} 

public void onClick(View v){ 


    qoItemNumber.append(String.valueOf(v.getTag())); 



} 
+0

如果你知道如何文本添加到字符串,刪除它是不是所有的不同... –

+0

我可以刪除整個字符串,但要刪除每次點擊一個號碼,我不知道該怎麼做。 –

+0

http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#substring%28int,%20int%29是字符串...使用字符串操作... –

回答

0

只需使用下面的方法刪除您編輯文本最後一個字符時間:

String str = youredittext.getText().toString().trim(); 
if(str.length()!=0){ 
str = str.substring(0, str.length() - 1); 
youredittext.setText (str); 

讓我知道如果你有關於任何疑問一樣。