2011-06-26 11 views
0

のタイプがであるNetworkListクラスがあります。私はit.butで私は新しい活動でarraylistの最初の要素だけを取得しているパーセル可能なインターフェイスを使用しています。 どのようにすべての要素を取得できますか? はここ2つのアクティビティ間でデータを渡す方法

ここ
Intent(AllNetworkActivity.this,WorkActivity.class); 
      intent.putExtra("name",network); 
      startActivity(intent); 
    }}); 



} 

が、私はそれが

Bundle extras=getIntent().getExtras(); 
    NetworkList network=(NetworkList)extras.getParcelable("name"); 
    String name[]=new String[network.getname().size()]; 
    for(int i=0;i<network.getname().size();i++){ 
     name[i]=network.getname().get(i); 
    } 
    setListAdapter(new ArrayAdapter<String>(this,R.layout.work,name)); 

は私が知っているuは助けることができます願って取得する方法をここでNetworkListクラス

public class NetworkList implements Parcelable{ 
private ArrayList<String> name=new ArrayList<String>(); 
private ArrayList<String> id=new ArrayList<String>(); 



@SuppressWarnings("unchecked") 
public NetworkList(Parcel in) { 
    // TODO Auto-generated constructor stub 
    name=in.readArrayList(null); 
    id=in.readArrayList(null); 
} 



public NetworkList() { 
    // TODO Auto-generated constructor stub 
} 



public void setName(String tempValue) { 
    // TODO Auto-generated method stub 
    this.name.add(tempValue); 
} 



public void setid(String tempValue) { 
    // TODO Auto-generated method stub 
    this.id.add(tempValue); 
} 



@Override 
public int describeContents() { 
    // TODO Auto-generated method stub 
    return 0; 
} 



@Override 
public void writeToParcel(Parcel dest, int flags) { 
    // TODO Auto-generated method stub 
    dest.writeList(name); 
    dest.writeList(id); 
} 



public ArrayList<String> getname() { 
    return name; 
} 

public static final Creator<NetworkList> CREATOR = new Parcelable.Creator<NetworkList>() { 
    public NetworkList createFromParcel(Parcel in) { 
     return new NetworkList(in); 
    } 

    public NetworkList[] newArray(int size) { 
     return new NetworkList[size]; 
    } 

}; 
} 

である私はそれを渡すどこかで

+1

いくつかのコードを表示できますか? –

+0

私はコードを投稿しました。私はarraylistの最初の要素を取得しています – Arihant

答えて

0

AndroidのApplicationクラスも調べてください。すべてのアクティビティがアクセスできるグローバル変数を定義することができます。しかし、Bundleはアクティビティ間でデータを送信する最も一般的で正しい方法です。

0

適切な方法を使用してList<String>をシリアル化してみてください:

public NetworkList(Parcel in) { 
    in.readStringList(name); 
    in.readStringList(id); 
} 


public void writeToParcel(Parcel dest, int flags) { 
    // log the number of elements - check that this is actually what you expect it to be 
    // use only during development 
    Log.i("NetworkList"," number of elements = "+name.size()) 

    dest.writeStringList(name); 
    dest.writeStringList(id); 
} 
+0

いいえまだ必要な結​​果が得られていません – Arihant

+1

要素の数を調べてから小包に書き出しましたか? 'Log.i()'行? –

+0

実際に私はthat.thanksを確認する方法を知らないurの答え – Arihant

0

最初

Intent Jan = new Intent(Months.this,Holiday.class); 
        Jan.putExtra("ListCount", "Jan"); 
        startActivity(Jan); 

その後、

Bundle extras = getIntent().getExtras(); 
     String data = extras.getString("ListCount"); 

     if(data.equals("Jan")){ 
      TextView txtMonth = (TextView)findViewById(R.id.txtMonth); 
      txtMonth.setText("January"); 

      TextView txtDetail = (TextView)findViewById(R.id.txtDetail); 
      txtDetail.setText(R.string.JanHol); 
     } 

check this post私は書いています。これがあなたを助けることを願っています。

関連する問題