我想在UI上面把一个键盘删除,不知道如何操作
这个键盘类是这样定义的class TouchInput implements View.OnClickListener,View.OnTouchListener
{

int digit = -1;
    private TextView mZero;
    private TextView mOne;
    private TextView mTwo;
    private TextView mThree;
    private TextView mFour;
    private TextView mFive;
    private TextView mSix;
    private TextView mSeven;
    private TextView mEight;
    private TextView mNine;
    private TextView mOk;
    private TextView mCancelButton;    TouchInput() {
        mZero = (TextView) findViewById(R.id.zero);
        mOne = (TextView) findViewById(R.id.one);
        mTwo = (TextView) findViewById(R.id.two);
        mThree = (TextView) findViewById(R.id.three);
        mFour = (TextView) findViewById(R.id.four);
        mFive = (TextView) findViewById(R.id.five);
        mSix = (TextView) findViewById(R.id.six);
        mSeven = (TextView) findViewById(R.id.seven);
        mEight = (TextView) findViewById(R.id.eight);
        mNine = (TextView) findViewById(R.id.nine);
mCancelButton = (TextView) findViewById(R.id.dismiss);

        if (PowerOnUnlockSIMLock.this.getResources().getBoolean(R.bool.sim_network_unlock_allow_dismiss)) {

mCancelButton.setOnTouchListener(this);
mCancelButton.setOnClickListener(this);
        } else {
mCancelButton.setText("");
        }

        mOk = (TextView) findViewById(R.id.ok);        mZero.setText("0");
        mOne.setText("1");
        mTwo.setText("2");
        mThree.setText("3");
        mFour.setText("4");
        mFive.setText("5");
        mSix.setText("6");
        mSeven.setText("7");
        mEight.setText("8");
        mNine.setText("9");        mZero.setOnClickListener(this);
        mOne.setOnClickListener(this);
        mTwo.setOnClickListener(this);
        mThree.setOnClickListener(this);
        mFour.setOnClickListener(this);
        mFive.setOnClickListener(this);
        mSix.setOnClickListener(this);
        mSeven.setOnClickListener(this);
        mEight.setOnClickListener(this);
        mNine.setOnClickListener(this);
        mOk.setOnClickListener(this);
        //mCancelButton.setOnClickListener(this);
        
        mZero.setOnTouchListener(this);
        mOne.setOnTouchListener(this);
        mTwo.setOnTouchListener(this);
        mThree.setOnTouchListener(this);
        mFour.setOnTouchListener(this);
        mFive.setOnTouchListener(this);
        mSix.setOnTouchListener(this);
        mSeven.setOnTouchListener(this);
        mEight.setOnTouchListener(this);
        mNine.setOnTouchListener(this);
        mOk.setOnTouchListener(this);
        //mCancelButton.setOnTouchListener(this);
    }  

解决方案 »

  1.   

      //To change button color while touch the button
        public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub
         Resources resources = getBaseContext().getResources();
    if(event.getAction() == MotionEvent.ACTION_DOWN){
    v.setBackgroundDrawable(resources.getDrawable(R.drawable.btnkeyboradclick));
    }else if(event.getAction() == MotionEvent.ACTION_UP){
    if(v == mOne || v == mTwo){
    v.setBackgroundDrawable(resources.getDrawable(R.drawable.btnnokeyboradunclicka));
    }else if(v == mThree){
    v.setBackgroundDrawable(resources.getDrawable(R.drawable.btnnokeyboradunclicke));
    }else if (v == mFour || v == mFive){
    v.setBackgroundDrawable(resources.getDrawable(R.drawable.btnnokeyboradunclickb));
    }else if(v == mSix){
    v.setBackgroundDrawable(resources.getDrawable(R.drawable.btnnokeyboradunclickf));
    }else if(v == mSeven || v == mEight){
    v.setBackgroundDrawable(resources.getDrawable(R.drawable.btnnokeyboradunclickc));
    }else if(v == mNine){
    v.setBackgroundDrawable(resources.getDrawable(R.drawable.btnnokeyboradunclickg));
    }else if(v == mOk){
    v.setBackgroundDrawable(resources.getDrawable(R.drawable.btnnokeyboradunclickj));
    }else if(v == mZero){
    v.setBackgroundDrawable(resources.getDrawable(R.drawable.btnnokeyboradunclickd));
    } /*add by lijiangtao*/
    else if(v == mCancelButton){
                 if (PowerOnUnlockSIMLock.this.getResources().getBoolean(R.bool.sim_network_unlock_allow_dismiss)) {
    v.setBackgroundDrawable(resources.getDrawable(R.drawable.btnnokeyboradunclickh));
                 
                 } else {
                 }

    } else{

    }
    }
    return false;
        }
      

  2.   

        public void onClick(View v) {        if (PowerOnUnlockSIMLock.this.getResources().getBoolean(R.bool.sim_network_unlock_allow_dismiss)) {
    if (v == mCancelButton)
                {
                         Log.d(LOGTAG, "[onClick][mCandelButton]+");
                            sendVerifyResult(VERIFY_TYPE_SIMMELOCK,false);
                        
                          if(iSIMMEUnlockNo == 0){
                          PhoneApp.arySIMLockStatus[0] = 0;//SIM 1 already dealt
                          Log.d(LOGTAG,"[changed][arySIMLockStatus]: ["+ PhoneApp.arySIMLockStatus[0] + " , " + PhoneApp.arySIMLockStatus[1] + " ]");         
                            if(PhoneApp.arySIMLockStatus[1] == 2){//Need to unlock SIM2
                            Intent intent = new Intent(PowerOnUnlockSIMLock.this, PowerOnSetupUnlockSIMLock.class);  
                            Bundle bundle = new Bundle();                                
                            bundle.putInt("Phone.GEMINI_SIM_ID_KEY",1);//To unlock which card  default:-1, Slot1: 0, Slot2:1
                            intent.putExtras(bundle);
                            startActivity(intent); 
                            }
                            setSimLockScreenDone(0,SIMLOCK_TYPE_SIMMELOCK);
                            Intent t = new Intent("action_melock_dismiss");
                            t.putExtra("simslot", 0);
                            PowerOnUnlockSIMLock.this.sendBroadcast(t);
                            PowerOnUnlockSIMLock.this.finish();
                            return;                                 
                        }else if(iSIMMEUnlockNo == 1){
                        PhoneApp.arySIMLockStatus[1] = 0;//SIM 1 already dealt
                        Log.d(LOGTAG,"[changed][arySIMLockStatus]: ["+ PhoneApp.arySIMLockStatus[0] + " , " + PhoneApp.arySIMLockStatus[1] + " ]");
                        if(PhoneApp.arySIMLockStatus[0] == 2){//Need to unlock SIM2
                            Intent intent = new Intent(PowerOnUnlockSIMLock.this, PowerOnSetupUnlockSIMLock.class);  
                            Bundle bundle = new Bundle();                                
                            bundle.putInt("Phone.GEMINI_SIM_ID_KEY",0);//To unlock which card  default:-1, Slot1: 0, Slot2:1
                            intent.putExtras(bundle);
                            startActivity(intent);
                         }
                        setSimLockScreenDone(1,SIMLOCK_TYPE_SIMMELOCK);
                            Intent t = new Intent("action_melock_dismiss");
                            t.putExtra("simslot", 1);
                            PowerOnUnlockSIMLock.this.sendBroadcast(t);
                         PowerOnUnlockSIMLock.this.finish();
                         return;                                 
                        }
                        Log.d(LOGTAG, "[onClick][mCandelButton]-");
                        return ;
                     }

            }

             //Cancel Button End
            if (v == mOk) {        
             if (mPwdDisplay != null){
             strPwd = mPwdDisplay.getText().toString();
             PwdLength = strPwd.length();
             if(bStringValid(strPwd) == false){
              mUnlockResultNotify.setText(getString(R.string.simlock_input4_8digits)); 
             }else{
                 if((PwdLength >= 4) && (PwdLength <= 8)){
                  //progressDialog =ProgressDialog.show(PowerOnPowerOnUnlockSIMLock.this,"","Unlocking....");
                  progressDialog = new ProgressDialog(PowerOnUnlockSIMLock.this);
                  progressDialog.setMessage(getString(R.string.simlock_unlocking));
                  progressDialog.setIndeterminate(true);
                  progressDialog.setCancelable(false);
                  progressDialog.getWindow().setType(
                                 WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
                  /*progressDialog.getWindow().setFlags(
                                    WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
                                    WindowManager.LayoutParams.FLAG_BLUR_BEHIND);*/
                  progressDialog.show();
                      //Process Unlock SIM Lock
                         if(false == FeatureOption.MTK_GEMINI_SUPPORT){
                          Message callback = Message.obtain(mHandler,  UNLOCK_ICC_SML_COMPLETE);
                             //Single Card:
                          Phone phone = PhoneFactory.getDefaultPhone();
                          phone.getIccCard().supplyNetworkDepersonalization(mPwdDisplay.getText().toString(),callback);
                          Log.d(LOGTAG, "[onClick][mOK][Single Card][SetSIMLock]+" + mPwdDisplay.getText().toString());
                         }else{
                          Log.d(LOGTAG, "[onClick][mOK][Gemini Card][SetSIMLock]+" + mPwdDisplay.getText().toString());
                          GeminiPhone mGeminiPhone = (GeminiPhone)PhoneFactory.getDefaultPhone();
                          if (iSIMMEUnlockNo == 0){
                           Log.d(LOGTAG, "[onClick][mOK][Gemini Card][SetSIMLock][SIM 1]+" );
                           Message callback = Message.obtain(mHandler,  UNLOCK_ICC_SML_COMPLETE);
                                  mGeminiPhone.getIccCardGemini(Phone.GEMINI_SIM_1).supplyNetworkDepersonalization(mPwdDisplay.getText().toString(),callback);
                           Log.d(LOGTAG, "[onClick][mOK][Gemini Card][SetSIMLock][SIM 1]-" );
                          }else if (iSIMMEUnlockNo == 1){
                          Log.d(LOGTAG, "[onClick][mOK][Gemini Card][SetSIMLock][SIM 2]+" );
                          Message callback = Message.obtain(mHandler,  UNLOCK_ICC_SML_COMPLETE);
                              mGeminiPhone.getIccCardGemini(Phone.GEMINI_SIM_2).supplyNetworkDepersonalization(mPwdDisplay.getText().toString(),callback);
                              Log.d(LOGTAG, "[onClick][mOK][Gemini Card][SetSIMLock][SIM 2]-" );
                          }
                          Log.d(LOGTAG, "[onClick][mOK][Gemini Card][SetSIMLock]-" );
                     }              }else{
                  //Notify the user to input 4---8 digits
                  mUnlockResultNotify.setText(getString(R.string.simlock_input4_8digits)); 
                 }
             }
     
             strPwd = null;//delete number entered before
             mPwdDisplay.setText("");    
             } 
            }//if (v == mOK)  End
            
            
            Log.d(LOGTAG, "[onClick][digit]");
            int keyEventCode = checkDigit(v);
            if (keyEventCode >= 0) {
             if (mPwdDisplay != null){
                 strPwd = mPwdDisplay.getText().toString();
                 PwdLength = strPwd.length();
                 if(PwdLength < 8){
                  strPwd += String.valueOf(digit);
                  sendDownUpKeyEvents(keyEventCode);
                 }
                 
                 //mPwdDisplay.setText(strPwd);//add digit to display on the Pwd edittext
            
                 }
             //showAlertDialog(DIALOG_ENTERNUMBER);//Show dialog of pressed number key for test
             digit = -1;
            
            }
        }//onClick() End
        
        private int checkDigit(View v) {
            int keyEventCode = -1;
            if (v == mZero) {
                digit = 0;
                keyEventCode = KeyEvent.KEYCODE_0;
            } else if (v == mOne) {
                digit = 1;
                keyEventCode = KeyEvent.KEYCODE_1;
            } else if (v == mTwo) {
                digit = 2;
                keyEventCode = KeyEvent.KEYCODE_2;
            } else if (v == mThree) {
                digit = 3;
                keyEventCode = KeyEvent.KEYCODE_3;
            } else if (v == mFour) {
                digit = 4;
                keyEventCode = KeyEvent.KEYCODE_4;
            } else if (v == mFive) {
                digit = 5;
                keyEventCode = KeyEvent.KEYCODE_5;
            } else if (v == mSix) {
                digit = 6;
                keyEventCode = KeyEvent.KEYCODE_6;
            } else if (v == mSeven) {
                digit = 7;
                keyEventCode = KeyEvent.KEYCODE_7;
            } else if (v == mEight) {
                digit = 8;
                keyEventCode = KeyEvent.KEYCODE_8;
            } else if (v == mNine) {
                digit = 9;
                keyEventCode = KeyEvent.KEYCODE_9;
            }
            return keyEventCode;
        }//checkDigit() end
          }