[英]How to pass arrays to a subactivity (android)?
我的程序基本上是項目列表,當您單擊項目時,它會將您發送到可擴展列表。 問題是,我的項目列表長了數百個項目,因此必須為每個項目創建一個不同的可擴展列表類,這很繁瑣。 相反,我想根據按下的列表選項將不同的數組發送到一個子活動。
這是我的主要活動中應發送信息的代碼部分:
if ((String) ((TextView) view).getText() == "Name of List Item") {
Intent myIntent = new Intent(view.getContext(),
SubActivity.class);
myIntent.putExtra("parents", new String[] { "bunch of parents" });
myIntent.putExtra("children", new String[][] {
{ "bunch" },
{ "of" },
{ "children"} });
startActivityForResult(myIntent, 0); }
這是我應該接收的代碼部分:
String[] parents; //declared outside onCreate() so they can be used by methods like createParentList()
String[][] children;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle b = this.getIntent().getExtras();
moves = b.getStringArray("parents");
parents = (String[][]) b.getSerializable("children");
我繼續嘗試將createParentList()/ createChildList()等用於可擴展列表。 它編譯得很好。 但是,每當我運行它並嘗試單擊列表項時,它都表明該過程已意外停止。 有人知道哪里出問題了嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.