繁体   English   中英

如何在另一个活动中传递数组字符串url?

[英]how can i pass array string url in another activity?

我的主要活动视频列表显示在主屏幕中,并且我将按钮设置在抽屉中,我想在我单击url home时在主屏幕中显示4个按钮,这样可以向我显示url home或url_one如何传递这些链接请帮帮我。

说明:在主屏幕上显示home_url,我在另一个活动主屏幕按钮中设计了四个按钮,即第一链接,第二链接和收藏夹按钮。 在这里,我称抽屉按钮中的链接为我要附加的按钮,该按钮在我的主要活动中显示主页按钮1st链接2nd链接和收藏夹按钮,当我单击旨在显示home_url字符串并向我显示视频列表的主页按钮时对于其他按钮。 请帮帮我

public class MainActivity extends AppCompatActivity implementsNavigationView.OnNavigationItemSelectedListener, AbsListView.OnScrollListener {



}

使用Intent。

String message = "hello there";    
Intent intent = new Intent(MainActivity.this, NextActivity.class);
intent.putExtra("message", message);
startActivity(intent);

在您要进行的活动中,本例中为NextActivity。

Bundle bundle = getIntent().getExtras();
String message = bundle.getString("message");

使用它

TextView textView = (TextView) findViewById(R.id.textView);  
textView.setText(message);

请注意, bundle是Android系统中用于组件间通信的关键组件之一。 您只需要考虑如何将Array放入该捆绑包中即可。

发送方:

        Intent intent1 = new Intent(MainActivity.this, NextActivity.class);
        Bundle bundle = new Bundle(); 
        ArrayList<String> arrayList = new ArrayList<String>();
        arrayList.add("17 Fake Street");
        arrayList.add("Phoney town");
        arrayList.add("Makebelieveland");

/* you can add more string values in your arrayList */

        bundle.putStringArrayList("myArrayListKey", arrayList);
        intent1.putExtra(bundle);

        startActivity(intent1);

接收方:

Bundle bundle = getIntent().getExtras(); /* you got the passsed bundle */
ArrayList<String> arrayList = bundle.getStringArray("myArrayListKey");  
/* you got the your passed ArrayList<String> */

/* now you can process your ArrayList<String> which you asked */

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM