Android中控件的OnKeyListener()事件


今天練習一下控件的鍵盤事件!也就是onKey事件!

練習題目:

    在編輯框中輸入、在文本框中實時的顯示!

代碼:

 public class LinkifyActivity extends Activity {
     TextView url;
     EditText urlTwo;

     @Override
     protected void onCreate(Bundle savedInstanceState) {
     // TODO Auto-generated method stub
         super.onCreate(savedInstanceState);
         this.setContentView(R.layout.linkify);
         url = (TextView)findViewById(R.id.textOne);
         urlTwo = (EditText)findViewById(R.id.editOne);
         urlTwo.setOnKeyListener(new EditText.OnKeyListener(){

         public boolean onKey(View v, int keyCode, KeyEvent event) {
             url.setText(urlTwo.getText().toString());
             return false;
         } 
         });
     } 
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM