呼び出しもと
java
1@Override 2 public Fragment getItem(int position) { 3 4 Bundle bundle = new Bundle();; 5 6 bundle.putInt("position",position); 7 8 CountryFragment fragment = new CountryFragment(); 9 fragment.setArguments(bundle); 10 11 getFragmentManager().beginTransaction().add(R.id.container,fragment,"TAG").commit(); 12 13 return fragment; 14 }
フラグメントクラス
hava
1public class CountryFragment extends Fragment implements View.OnClickListener,AdapterView.OnItemClickListener{ 2 3 // シングルトンで生成 4 private static CountryFragment mCountryFragment; 5 6 private Context mContext; 7 8 private LinearLayout mRoot; 9 private ListView listView; 10 11 private static int number; 12 private static Tab tab; 13 14 private CollectionListAdapter mCollectionListAdapter; 15 private List<Collection> collectionList; 16 17 18 public static CountryFragment newInstance(int position){ 19 mCountryFragment = new CountryFragment(); 20 number = position; 21 return mCountryFragment; 22 } 23 24 public static CountryFragment getInstance(){ 25 return mCountryFragment; 26 } 27 28 // 空のコンストラクタ必要 29 public CountryFragment() {} 30 31 @Override 32 public void onAttach(Context context){ 33 super.onAttach(context); 34 mContext = context; 35 } 36 37 // ビューを生成 38 @Override 39 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceSate){ 40 return inflater.inflate(R.layout.fragment_all,container,false); 41 } 42 43 @Override 44 public void onResume(){ 45 super.onResume(); 46 } 47 48 49 // こっちもビューを生成 50 @Override 51 public void onViewCreated(View view, Bundle savedInstanceState){ 52 super.onViewCreated(view, savedInstanceState); 53 54 // View初期化 55 mRoot = (LinearLayout)view.findViewById(R.id.root); 56 57 listView = (ListView) view.findViewById(R.id.list_collection); 58 listView.setOnItemClickListener(this); 59 listView.setOnCreateContextMenuListener(this); 60 ListView listView = (ListView)getView().findViewById(R.id.list_collection); 61 CollectionListAdapter adapter = (CollectionListAdapter)listView.getAdapter(); 62 collectionList = testView(number); 63 64 if(adapter == null){ 65 adapter = new CollectionListAdapter(getActivity(), collectionList); 66 listView.setAdapter(adapter); 67 } 68 adapter.updateCollectionList(collectionList); 69 } 70 71public List<Collection> testView(int number){ 72 List<Collection> collectionList = new ArrayList<>(); 73 74 if(number == 0){ 75 Collection collection1 = new Collection(0); 76 collection1.setName("テスト1"); 77 collection1.setType1(1); 78 collection1.setAmazon("http://xxxxxx.com"); 79 collectionList.add(collection1); 80 }else if(number ==1){ 81 Collection collection1 = new Collection(0); 82 collection1.setName("テスト1"); 83 collection1.setType1(1); 84 collection1.setAmazon("http://xxxxxx.com"); 85 collectionList.add(collection1); 86 Collection collection2 = new Collection(0); 87 collection2.setName("テスト2"); 88 collection2.setType1(2); 89 collection2.setAmazon("http://xxxxxx2.com"); 90 collectionList.add(collection1); 91 }else if(number==2){ 92 Collection collection1 = new Collection(0); 93 collection1.setName("テスト1"); 94 collection1.setType1(1); 95 collection1.setAmazon("http://xxxxxx.com"); 96 collectionList.add(collection1); 97 Collection collection2 = new Collection(0); 98 collection2.setName("テスト1"); 99 collection2.setType1(2); 100 collection2.setAmazon("http://xxxxxx.com"); 101 collectionList.add(collection2); 102 Collection collection3 = new Collection(0); 103 collection3.setName("テスト1"); 104 collection3.setType1(3); 105 collection3.setAmazon("http://xxxxxx.com"); 106 collectionList.add(collection3); 107 }else{ 108 Collection collection1 = new Collection(0); 109 collection1.setName("テスト1"); 110 collection1.setType1(1); 111 collection1.setAmazon("http://xxxxxx.com"); 112 collectionList.add(collection1); 113 Collection collection2 = new Collection(0); 114 collection2.setName("テスト1"); 115 collection2.setType1(2); 116 collection2.setAmazon("http://xxxxxx.com"); 117 collectionList.add(collection2); 118 Collection collection3 = new Collection(0); 119 collection3.setName("テスト1"); 120 collection3.setType1(3); 121 collection3.setAmazon("http://xxxxxx.com"); 122 collectionList.add(collection3); 123 Collection collection4 = new Collection(0); 124 collection4.setName("テスト1"); 125 collection4.setType1(4); 126 collection4.setAmazon("http://xxxxxx.com"); 127 collectionList.add(collection4); 128 } 129 130 return collectionList; 131 132 }
アプリを一旦終了し、ブラウザも完全閉じた上で、、アプリを起動しタブ画面を表示してみると、なぜか1つ目の全画面データに全部表示されず、2つ目のリストが表示されるようになります。
その後に3ページ目以降に一枚目を見るとちゃんとデータが表示されています
何かおかしなコードはありますでしょうか?
ご教授のほど宜しくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/28 01:20