• 06_键盘事件



    import android.os.Bundle;
    import android.app.Activity;
    import android.util.Log;
    import android.view.KeyEvent;
    import android.view.Menu;
    import android.view.View;
    import android.view.View.OnKeyListener;
    import android.widget.TextView;

    public class MainActivity extends Activity implements OnKeyListener {
        StringBuilder builder = new StringBuilder();
         TextView textView;

         public void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             textView = new TextView(this);
             textView.setText("Press keys (if you have some)!");
             textView.setOnKeyListener(this);
             textView.setFocusableInTouchMode(true);
             textView.requestFocus();
             setContentView(textView);
         }

         @Override
         public boolean onKey(View view, int keyCode, KeyEvent event) {
             builder.setLength(0);
             switch (event.getAction()) {
             case KeyEvent.ACTION_DOWN:
                 builder.append("down, ");
                 break;
             case KeyEvent.ACTION_UP:
                 builder.append("up, ");
                 break;
             }
             builder.append(event.getKeyCode());
             builder.append(", ");
             builder.append((char) event.getUnicodeChar());
             String text = builder.toString();
             Log.d("KeyTest", text);
             textView.setText(text);

             if (event.getKeyCode() == KeyEvent.KEYCODE_BACK)
                 return false;
             else
                 return true;
         }
     }

  • 相关阅读:
    降维-基于RDD的API
    GraphX编程指南
    GPU自动调度卷积层
    TVM部署预定义模型
    做个普通人,就挺好的
    Spring 的 @Primary 注解
    微信公众平台消息接口开发(30)大众点评商户信息团购及优惠券查询
    大众点评API获取某坐标周边酒店信息
    Sharding-jdbc 读写分离(三)- springboot+mybatis+Hikari
    Sharding-jdbc 分库分表专题内容(二)springboot+mybatis+Hikari
  • 原文地址:https://www.cnblogs.com/xl711436/p/3060415.html
Copyright © 2020-2023  润新知