In the Android operating system, if you want to perform specific operations on a control, You Need To trigger the corresponding event. For example, the Android onKey event is triggered. Here we will give you a detailed introduction to some related operation skills of Android onKey.
Added a GridView to the Activity subclass Gstock,
- setContentView(R.layout.gstock);
- GridView gridview = (GridView) findViewById(R.id.gridviewMain);
And set
- gridview.setOnItemClickListener(new GstockGridViewItemClickListener(this));
Click "select" and then reset Gstock.
- setContentView(new MyStock(this.g));
In this case, MyStock extends SurfaceView implements SurfaceHolder. Callback and OnKeyListener
- Public MyStock (Context context ){
- Super (context );
- Holder = this. getHolder ();
- Holder. addCallback (this );
- This. setFocusable (true );
- This. setOnKeyListener (this); // listens to the onKey event
- }
From the screen of the GridView to MyStock, sometimes the Android onKey event cannot be triggered, which is very strange. It can be triggered sometimes. It is a simulator problem ????
Unable to listen: When the GridView has a focus, that is, when the screen above the point simulator has a background.
When the mouse clicks the GridView, there is no focus, and there is no background after it is clicked.
The specific operations of Android onKey are described here.