//////////////使用窗口作为监听器。 public class index extends Activity implements OnClickListener{ Button bs0,bs1,bs2,bs3,bs4,bs5,bs6,bs7,bs8,bs9,call,c; EditText edit; Button del; private static final int COUNT=0; public int bi[]={R.id.i0,R.id.i1,R.id.i2,R.id.i3,R.id.i4,R.id.i5,R.id.i6,R.id.i7,R.id.i8,R.id.i9}; bs0=(Button) findViewById(bi[0]); bs1=(Button) findViewById(bi[1]); bs2=(Button) findViewById(bi[2]); bs3=(Button) findViewById(bi[3]); bs4=(Button) findViewById(bi[4]); bs5=(Button) findViewById(bi[5]); bs6=(Button) findViewById(bi[6]); bs7=(Button) findViewById(bi[7]); bs8=(Button) findViewById(bi[8]); bs9=(Button) findViewById(bi[9]); edit=(EditText) findViewById(R.id.edit); call=(Button) findViewById(R.id.call); c=(Button) findViewById(R.id.c); del=(Button) findViewById(R.id.del); bs0.setOnClickListener(this); bs1.setOnClickListener(this); bs2.setOnClickListener(this); bs3.setOnClickListener(this); bs4.setOnClickListener(this); bs5.setOnClickListener(this); bs6.setOnClickListener(this); bs7.setOnClickListener(this); bs8.setOnClickListener(this); bs9.setOnClickListener(this); call.setOnClickListener(this); c.setOnClickListener(this); del.setOnClickListener(this); } ///////////////重写onClick()方法 public void onClick(View v) { //////////////使用HashMap把按钮当成键把数字当成值 Integer i0=0,i1=1,i2=2,i3=3,i4=4,i5=5,i6=6,i7=7,i8=8,i9=9,d=10,ca=11,c1=12; HashMap bf=new HashMap(); bf.put(bs0, i0);bf.put(bs1, i1);bf.put(bs2, i2);bf.put(bs3, i3);bf.put(bs4, i4);bf.put(bs5, i5);bf.put(bs6, i6); bf.put(bs7, i7);bf.put(bs8, i8);bf.put(bs9, i9);bf.put(del, d);bf.put(call, ca);bf.put(c, c1); Button bbs=(Button)v; int ii=bf.get(v); if (ii<10){ String s1=String.valueOf(ii); edit.append(s1); } //////////////////在根据获取的数字的值不同来为不同的按钮或其他的控件来添加它们的单击事件。 else if(ii==10){ String s3=edit.getText().toString(); System.out.print(s3); s3=(s3.length()>1)?s3.substring(0,s3.length()-1):""; edit.setText(s3); } else if (ii==11){ } else if(ii==12){ index.this.finish(); } } //java/6800