我有一个父容器,里面有一个ViewPager。我在ViewPagerAdapter中膨胀ViewPager来设置滑块。除了移动滑块,我需要引用ViewPager父级,以便我可以在其中填充文本字段。
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.viewpager_item, container,
false);
如何从itemView?
引用父容器中的文本字段完整代码 -
View itemView = inflater.inflate(R.layout.viewpager_item, container,
false);
View fragmentView=inflater.inflate(R.layout.fragment_first_scroll_view, container, false);
// Locate the TextViews in viewpager_item.xml
txtrank = (TextView) itemView.findViewById(R.id.rank);
txtcountry = (TextView) itemView.findViewById(R.id.country);
//txtpopulation = (TextView) itemView.findViewById(R.id.population);
txtpopulation=(TextView) fragmentView.findViewById(R.id.population);
// Capture position and set to the TextViews
txtrank.setText(rank[position]);
txtcountry.setText(country[position]);
System.out.println(population[position]);
txtpopulation.setText(population[position]);
// Locate the ImageView in viewpager_item.xml
imgflag = (ImageView) itemView.findViewById(R.id.flag);
// Capture position and set to the ImageView
imgflag.setImageResource(flag[position]);
// Add viewpager_item.xml to ViewPager
((ViewPager) container).addView(itemView);
return itemView;