■前提
・動的に作られるViewがあり、数が分からない。(下のコードのmapInfoItem)
■やりたいこと
・そこにFragment、正確にはSupportMapFragmentを追加して地図を表示したい。
■やってみたこと
・以下のようにtransaction.add(mapLayout.getId(), mapFragment);だと、idが毎回同じIDが入ってくるので、地図は一番上にしか表示されなかった。
■質問
ID指定ではない方法でFragmentを動的に複数追加する方法はあるでしょうか?
java
1for (int i = 0; i < 10; i++) { // 10は仮で数は分からない 2 LayoutInflater inflater = LayoutInflater.from(this); 3 View mapInfoItem = inflater.inflate(R.layout.article_map_info_item, null); 4 View mapLayout = mapInfoItem.findViewById(R.id.map_layout); 5 LogU.d("mapLayout.getId()", String.valueOf(mapLayout.getId())); 6 7 SupportMapFragment mapFragment = SupportMapFragment.newInstance(); 8 9 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 10 transaction.add(mapLayout.getId(), mapFragment); // ここのmapLayout.getId()が毎回同じ値になってしまうので地図が一番上しか出てこない 11 transaction.commit(); 12 13 ((LinearLayout)findViewById(R.id.content_layout)).addView(mapInfoItem); 14}
◆環境
Android studio 2.3.3
min sdk 21
target sdk 26
compile sdk 26
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/21 23:47