【问题标题】:How to navigate to another screen [duplicate]如何导航到另一个屏幕[重复]
【发布时间】:2011-08-23 09:53:16
【问题描述】:

可能重复:
How to navigate from one screen to another screen

我是安卓开发新手。你能告诉我,如何从一个活动屏幕导航到另一个活动屏幕。在第一个屏幕中,我有一个由 4 个组件组成的 ListView,如果我点击其中一个组件,它必须移动到另一个活动屏幕。 新屏幕应该执行什么方法才能转到下一个屏幕。
我正在添加我的代码以供参考。 GetParameter.class 是要调用的新活动。这是行不通的。可能是什么原因?

       public void onListItemClick(ListView parent, View v, int position, long id) 
   {
    if (position == 0) {

        startActivity(new Intent(this, GetParameter.class));

        GlobalFunctions.startCommonDate(1, 2, 1);
        startActivity(new Intent(this, newone.class));

    } else if (position == 1) {
        GlobalFunctions.startCommonDate(2, 2, 1);
        startActivity(new Intent(this, newone.class));

    } else if (position == 2) {
        GlobalFunctions.startCommonDate(3, 2, 1);
        startActivity(new Intent(this, newone.class));

    } else if (position == 3) {
        start_Customdate();
    }

}`

【问题讨论】:

标签: android


【解决方案1】:

试试这个

 startActivity(new Intent(From.this,To.class));

同样在清单文件中签名所有你使用的活动

【讨论】:

    【解决方案2】:

    Android 使用 Intent 对象在活动之间发送消息以及打开/启动新活动。

    我建议您阅读以下内容: http://www.vogella.de/articles/AndroidIntent/article.html 和/或完成以下 3 个练习: http://developer.android.com/resources/tutorials/notepad/index.html

    【讨论】:

      【解决方案3】:
      Intent intent=new Intent(source.this,destination.class);
      startActivity(intent);
      

      【讨论】:

      • 请在您的答案中提供文档链接和一些解释,而不仅仅是编写代码。
      • @Merlin 如果你提供代码。你也有练习。所以最好提供代码而不是链接。
      • “而不是只是写代码”...我的意思是代码都带有引用的解释。
      【解决方案4】:

      你在你的点击监听器中开始一个新的意图

      ListView lv = getListView();
      lv.setOnItemClickListener(adapterAndListener);
      
      lv.setOnItemClickListener(new OnItemClickListener() {
         public void onItemClick(AdapterView<?> parent, View view,
         int position, long id) {
      
            Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);
            CurrentActivity.this.startActivity(myIntent);
      
         }
      });
      

      您可以在以下示例中找到有关 ListView 的更多信息:

      http://developer.android.com/resources/tutorials/views/hello-listview.html

      【讨论】:

      • 我有两个方法 onCreate() 和 onListItemClick()。在哪里调用新活动...在 onCreate() 或 onListItemClick() 方法中?
      • 在 onListItemClick 方法中。如果你把它放在你的第一个活动的 onCreate 中,它会立即开始第二个活动。 :)
      【解决方案5】:

      我同意 Rasel 的回答。 除此之外,您可以考虑使用startActivityForResult() / onActivityResult() 如果您的女儿Activity 需要向其父母寄回一些东西。

      更多细节在这里:

      【讨论】:

        【解决方案6】:

        在你的listview onclick里面使用这个代码,

          Intent myIntent = new Intent(FirstActivity.this, secondActivity.class);
        

        【讨论】:

        • 他使用的是列表视图而不是按钮
        猜你喜欢
        • 2010-11-09
        • 2019-10-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-22
        • 2020-07-27
        • 1970-01-01
        相关资源
        最近更新 更多