問題一:java
按1 TextView 裏面顯示1後,按2,2把1替換了,顯示的是2,而不是12ide
解決辦法,添加兩個全局變量this
private String myString; private CharSequence temp;
activity 繼承implements OnClickListenerspa
findById部分省略不寫了code
btn1.setOnClickListener(this); btn2.setOnClickListener(this); back.setOnClickListener(this);
@Override public void onClick(View v) { switch (v.getId()) { case R.id.button1: myString += "1"; tv_text.setText(myString);//tv_test是TextView控件 break; case R.id.button2: myString += "2"; tv_text.setText(myString); break; case R.id.backspace://若是是回退刪除 try { myString = myString.substring(0, myString.length() - 1); tv_text.setText(myString); } catch (Exception e) { tel_text.setText(null); } break;