TShopping

 找回密碼
 註冊
搜索
TShopping 精選文章 Android 手機開發 查看內容

[Android智慧型手機設計_ContextMenu元件]

2013-7-10 19:52| 發佈者: woff| 查看: 319| 評論: 0|原作者: woff

摘要: package com.example.contextmenucctu; import android.os.Bundle; import android.app.Activity; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.Menu; ...
 
1.jpg

  1. package com.example.contextmenucctu;

  2. import android.os.Bundle;
  3. import android.app.Activity;
  4. import android.view.ContextMenu;
  5. import android.view.ContextMenu.ContextMenuInfo;
  6. import android.view.Menu;
  7. import android.view.MenuItem;
  8. import android.view.View;
  9. import android.widget.LinearLayout;
  10. import android.widget.Toast;

  11. public class MainActivity extends Activity {

  12. @Override
  13. protected void onCreate(Bundle savedInstanceState) {
  14. super.onCreate(savedInstanceState);
  15. setContentView(R.layout.activity_main);
  16. LinearLayout linear=(LinearLayout)findViewById(R.id.LinearLayout1);
  17. registerForContextMenu(linear);
  18. }

  19. @Override
  20. public void onCreateContextMenu(ContextMenu menu,View v,ContextMenuInfo of) {
  21. // Inflate the menu; this adds items to the action bar if it is present.
  22. getMenuInflater().inflate(R.menu.main, menu);
  23. }

  24. public boolean onContextItemSelected(MenuItem item)
  25. {
  26. String msg="";
  27. switch(item.getItemId())
  28. {
  29. case R.id.item1:
  30. msg=getString(R.string.m1);
  31. break;
  32. case R.id.item2:
  33. msg=getString(R.string.m2);
  34. break;
  35. case R.id.item3:
  36. msg=getString(R.string.m3);
  37. break;
  38. case R.id.item4:
  39. msg=getString(R.string.m4);
  40. break;
  41. case R.id.item5:
  42. finish();
  43. default:
  44. return super.onOptionsItemSelected(item);
  45. }
  46. Toast.makeText(MainActivity.this, msg, Toast.LENGTH_LONG).show();
  47. return true;
  48. }

  49. }
復制代碼

最新評論



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2017-4-28 13:02 , Processed in 0.039875 second(s), 21 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

返回頂部