开发学院手机开发Android 开发 Android Activity 中常见的控件 阅读

Android Activity 中常见的控件

 2010-09-10 01:12:00 来源:WEB开发网   
核心提示:16.17. /** Called when the activity is first created. */18. private Button button;19. private EditText editOne;20. private EditText editTwo;21. private TextView

16.

17. /** Called when the activity is first created. */

18. private Button button;

19. private EditText editOne;

20. private EditText editTwo;

21. private TextView textView;

22. @Override

23. public void onCreate(Bundle savedInstanceState) {

24. super.onCreate(savedInstanceState);

25. setContentView(R.layout.main);

26. //获取各个组件,并给其赋值

27. button=(Button)findViewById(R.id.button);

28. editOne=(EditText)findViewById(R.id.strOne);

29. editTwo=(EditText)findViewById(R.id.strTwo);

30. textView=(TextView)findViewById(R.id.strCheng);

31. button.setText(R.string.button);

32. textView.setText(R.string.strCheng);

33. button.setOnClickListener(new BclickListener());

34. }

35. //菜单选项的添加

36. @Override

37. public boolean onCreateOptionsMenu(Menu menu) {

38. // TODO Auto-generated method stub

39. menu.add(1, 1, 1, R.string.exit);

40. menu.add(1,2,2,R.string.about);

41. return super.onCreateOptionsMenu(menu);

42. }

43. //对菜单选项进行控制

44. @Override

45. public boolean onOptionsItemSelected(MenuItem item) {

46. // TODO Auto-generated method stub

47. if (item.getItemId()==1){

48. finish();

49. }

50. return super.onOptionsItemSelected(item);

51. }

52. class BclickListener implements OnClickListener{

53.

54. @Override

55. public void onClick(View v) {

56. Intent intent =new Intent();

57. intent.putExtra("one",editOne.getText().toString());

58. intent.putExtra("two", editTwo.getText().toString());

59. intent.setClass(Deom.this, Result.class);

60. Deom.this.startActivity(intent);

上一页  1 2 3 4 5 6  下一页

Tags:Android Activity 常见

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接