[英]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.