関連するクラス

Adapterと関連するクラス群

今まで下記4クラスの中のAdapterについて述べてきました。

RecyclerView

Adapter

ViewHolder

LayoutManager

Adapterに関連してViewHolderがRecycleViewの表示に必要です。

更に、ViewHolderとは別に「表示データ」を格納するクラスが必要です。

ViewHolder ➡ (Item) ➡ PlaceholderContentオブジェクト(データ集合を保持)

個々のデータをPlaceHolderItemと呼ぶことにします。

PlaceholderContentオブジェクト

これらを踏まえると次のコーディング例になります。

public class PlaceholderContent {

   /* PlaceholderItem 変換 Before */

   public static List DATALIST = new ArrayList();

   /**

    * An array of sample (placeholder) items.

    */

   public static List<PlaceholderItem> ITEMS = new ArrayList<PlaceholderItem>();

   public static void PlaceholderContent(List list) {

       DATALIST = new ArrayList(list);

       // Add some sample items.

       for (int i = 0; i < DATALIST.size(); i++) {

           /*  文字列としてファイルから読み込んだデータをItemにして */

           PlaceholderItem x = createPlaceholderItem(i);

           /*  Staticのエリアに設定する*/

           addItem(x);

       }

   }

   private static void addItem(PlaceholderItem item) {

       ITEMS.add(item);

   }

   private static PlaceholderItem createPlaceholderItem(int position) {

       return new PlaceholderItem(position);

   }

   /*

    * ******************************************************

    * A placeholder item representing a piece of content ***

    * (inner class)

    * *****************************************************

    */

   public static class PlaceholderItem implements Serializable {

       public final String renban; // 連番 格納順の発番番号

       public final String koneORotto; // 対象(コネ 夫 その他)

       public final String hizuke; // 日付

       public final String jikoku; // 時刻

       public final String dare; // 誰

       public final String nani; // 何

       public final String shurui; // 種類

       public final String hosoku; // 補足

       private PlaceholderItem(int position) {

           // リストから項目1行を取り出す

           String temp = DATALIST.get(position).toString();

           String[] strArr = temp.split(“\\s*,\\s*”);

           // 番号設定

           this.renban = “” + position;

           // 個別に値を取り出す

           this.koneORotto = (strArr[0] == null ? “” : strArr[0]);// 対象

           this.hizuke = (strArr[1] == null ? “” : strArr[1]);// 日付

           this.jikoku = (strArr[2] == null ? “” : strArr[2]); // 時刻

           this.dare = (strArr[3] == null ? “” : strArr[0]);// 誰

           this.nani = (strArr[4] == null ? “” : strArr[4]);// 何

           this.shurui = “”; //(strArr[5] == null ? “” : strArr[5]); // 種類

           this.hosoku = “”;  //(strArr[6] == null ? “” : strArr[6]); // 補足

       }

       // ************************************************

       // getter

       // ************************************************

コメント

タイトルとURLをコピーしました