【问题标题】:How can I make that this will open another layout? [duplicate]我怎样才能让它打开另一个布局? [复制]
【发布时间】:2014-01-24 20:48:20
【问题描述】:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
        case R.id.action_settings:

(我必须在这里写什么,应用程序将打开另一个活动?)

【问题讨论】:

    标签: android eclipse android-intent android-activity


    【解决方案1】:
    switch (item.getItemId()){
       case R.id.action_settings:
           Intent i = new Intent(this, AnotherActivity.class);
           startActivity(i);
           break;
    }
    

    【讨论】:

      【解决方案2】:

      写这个来打开一个新的活动-

      @Override
      public boolean onOptionsItemSelected(MenuItem item) 
      {
          // Handle presses on the action bar items
          switch (item.getItemId()) 
          {
              case R.id.action_settings:
      Intent intent = new Intent(YourCurrentActivity.this, NextActivity.class);
      startActivity(intent);
      

      【讨论】:

      • @divjad--- 不要忘记在 manifest.xml 中添加“NextActivity”
      猜你喜欢
      • 2021-05-29
      • 2021-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-25
      • 1970-01-01
      • 2019-06-30
      相关资源
      最近更新 更多