标签: 计算器 Android SDK
[3].[代码] main.java 跳至 [1] [2] [3] [4]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
package
com.pragmatouch.calculator;
import
android.app.Activity;
import
android.os.Bundle;
import
android.widget.AdapterView;
import
android.widget.GridView;
import
android.view.View;
import
android.view.View.OnClickListener;
public
class
main
extends
Activity {
GridView mKeypadGrid;
KeypadAdapter mKeypadAdapter;
/** Called when the activity is first created. */
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get reference to the keypad button GridView
mKeypadGrid = (GridView) findViewById(R.id.grdButtons);
// Create Keypad Adapter
mKeypadAdapter =
new
KeypadAdapter(
this
);
// Set adapter of the keypad grid
mKeypadGrid.setAdapter(mKeypadAdapter);
// Set button click listener of the keypad adapter
mKeypadAdapter.setOnButtonClickListener(
new
OnClickListener() {
@Override
public
void
onClick(View v) {
Button btn = (Button) v;
// Get the KeypadButton value which is used to identify the
// keypad button from the Button's tag
KeypadButton keypadButton = (KeypadButton) btn.getTag();
// Process keypad button
ProcessKeypadInput(keypadButton);
}});
});
mKeypadGrid.setOnItemClickListener(
new
OnItemClickListener() {
public
void
onItemClick(AdapterView<?> parent, View v,
int
position,
long
id) {
// This will not help us catch button clicks!
}
});
}
}
|