新增代碼:- public void delete(View view) {
- //show.setText(show.getText().subSequence(0,show.getText().length()-1)); 字串切割法
- if(show.getText().equals("")) //防止空按錯誤
- {
- show.setText("");
- }else {
- st.pop(); //stak堆疊法
- String output = "";
- for (String str : st) {
- output += str;
- }
- show.setText(output);
- }
- }
- Button.OnLongClickListener longClickListener = new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- show.setText("");
- st.clear();
- return true;
- }
- };
複製代碼 |