2011-11-19 4 views
7

私は、トーナメントオブジェクトをParcelableとして作成し、インテント間でそれらを渡すテストアプリケーションを実装しています。 トーナメントには、 が含まれます。 Aトーナメント名 ルール 。プレイヤーの一致ルール(ランダム/手動) 。Android Parcelable Implementation with ArrayList <Object>

Tournament.javaを

public class TournamentData implements Parcelable { 
private String tourName; 
private int bestOf; 
private boolean isRandom; 
private ArrayList<Player> playerList; 

public TournamentData(String name, int tourBestOf, boolean random) { 
    this.tourName = name; 
    this.bestOf = tourBestOf; 
    this.isRandom = random; 
} 

public void addPlayer(Player newPlayer) { 
    this.playerList.add(newPlayer); 
} 

public ArrayList<Player> getPlayerList() { 
    return playerList; 
} 

    /* getters and setters excluded from code here */ 

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

public void writeToParcel(Parcel out, int flags) { 
    // TODO Auto-generated method stub 

} 

Player.java

public class Player { 

private String playerName; 
private String playerEmail; 

public Player(String name, String email) { 
    this.playerName = name; 
    this.playerEmail = email; 
} 
    /* getter and setters are excluded */ 

}

:プレーヤー

の配列リストは、これは私がこれまで持っているものです私はAndroidに新しい(私は非常に新しいことを意味する;私はそれに10時間を推測する)。だから私は不思議です: 。 ArrayListを持つTournamentオブジェクトの仕様を与えられたParcelableオブジェクトを作成することは可能ですか? 。すべてのトーナメントデータをParcelableオブジェクトに格納し、他のアクティビティからそれらにアクセスする方法は? (すなわち、AおよびB)。

+2

チェックアウトparcleどのようにするための完全な例があり、この答えをお見せしたコードであるティム・ブレイ]

Parcelableを使用してarrayListを解析します。 http://stackoverflow.com/questions/7400564/android-parcelable-retailerorderactivity-java-return-null/7400675#7400675 –

+0

@LalitPoptani:プレーヤーオブジェクトもParcelableでなければなりませんか? –

+0

はい、そうするのが良いです。 –

答えて

0

これらのものの多くは、RPCのあることが判明 - 私は確かに、......

うんをしようその後、従来のJavaでの作業の大部分を記述します。

IBinder経由で送信できるメッセージ(データ参照およびオブジェクト参照)のコンテナです。パーセルには、IPCの反対側で平坦化されない平坦化されたデータ(特定のタイプを書くためのさまざまなメソッド、または一般的なParcelableインターフェイスを使用)と、他の側が受け取る結果となるライブIBinderオブジェクトへの参照Parcel内の元のIBinderに接続されたプロキシIBinder。小包は、プロセス間通信の形で他の言葉で

....

あなたはこれが10,000リクエスト第二のサーバがないように、ベースモデルを再考する必要があります - どのようなことがあることは手ですそれが持っている場合だけ、プロセステーブルからポインタを引き出すことができる-held民生機器へのそれは

を運営しているの私は、エントリをドリルダウンしないよう十分に注意してくださいhttp://android-developers.blogspot.com/?hl=en

でブログのタブに移動することを学んだので、ワーカースレッドに入れる必要のあるものと深くないものJavaは午前11時41分AM で2010年7月19日にティム・ブレイ投稿者パフォーマンス

について

マルチスレッドを使用して簡単に作る豊富な同期プリミティブTE [この投稿はジルDebunneに、エンジニアでありますマルチタスクになるのが大好きなAndroidグループでは、 - それはブログで---ここ

2

を開始するためのより良い場所はどのようにArrayListの

public class ParcleListTopic implements Parcelable{ 
    private List<ParcleTopic> list; 
    private ArrayList<HoldListTopic> listh=new ArrayList<HoldListTopic>(); 
    public ArrayList<HoldListTopic> GetListTopic() 
    { 
     for(int i=0;i<list.size();i++) 
     { 
      listh.add(list.get(i).GetHold()); 
     } 
     return listh; 
    } 
    public void writeToParcel(Parcel dest, int flags) { 
     dest.writeTypedList(list); 
    } 
    public ParcleListTopic(Parcel in) 
    { 
     in.readTypedList(list,ParcleTopic.CREATOR); 

    } 
    public ParcleListTopic(List<ParcleTopic> list) 
    { 
     this.list=list; 
    } 
    public static final Parcelable.Creator<ParcleListTopic> CREATOR = new Parcelable.Creator<ParcleListTopic>(){ 
      public ParcleListTopic createFromParcel(Parcel s) 
      { 
       return new ParcleListTopic(s); 
      } 
      public ParcleListTopic[] newArray(int size) 
      { 
       return new ParcleListTopic[size]; 
      } 
    }; 
    public int describeContents() { 
     // TODO Auto-generated method stub 
     return 0; 
    } 
} 


public class ParcleTopic implements Parcelable 
{ 
    HoldListTopic hold; 
    public ParcleTopic(HoldListTopic hold) 
    { 
     this.hold=hold; 
    } 
    public HoldListTopic GetHold() 
    { 
     return hold; 
    } 
    public int describeContents() 
    { 
     return 0; 
    } 
    public void writeToParcel(Parcel dest, int flags) 
    { 
     dest.writeString(hold.Title); 
     dest.writeString(hold.Date); 
     dest.writeInt(hold.NumberComment); 
     dest.writeInt(hold.ID); 
    } 
    public ParcleTopic(Parcel in) 
    { 
     hold.Title=in.readString(); 
     hold.Date=in.readString(); 
     hold.NumberComment=in.readInt(); 
     hold.ID=in.readInt(); 
    } 
    public static final Parcelable.Creator<ParcleTopic> CREATOR = new Parcelable.Creator<ParcleTopic>() 
    { 
      public ParcleTopic createFromParcel(Parcel s) 
      { 
       return new ParcleTopic(s); 
      } 
      public ParcleTopic[] newArray(int size) 
      { 
       return new ParcleTopic[size]; 
      } 
    }; } 
関連する問題