Viewpager与Android的标签 [英] Viewpager with tabs android
问题描述
我要提供刷卡设施的标签导航。对于我已经尝试本。
I want to provide tab navigation with swipe facility. For that i have tried THIS.
链接显示了用viewpager标签。类TestFragment.java是添加静态视图和类可以在此链接上找到:<一href=\"https://github.com/JakeWharton/Android-ViewPagerIndicator/blob/master/sample/src/com/viewpagerindicator/sample/TestFragment.java\"相对=nofollow>在这里结果
但我想添加动态views.Is这可能吗?结果
请建议如何实现呢?
Link which shows tabs with viewpager. The class TestFragment.java is adding static views and class can be found at this link : Here
But i want to add dynamic views.Is it possible ?
Please suggest how to implement it ?
感谢。
推荐答案
我已经做了类似的事情,我创造了基本的片段布局,然后叫从片段内的函数 FragmentActivity
,然后更新视图。
I've done something similar where I created the basic fragment layouts, then called a function inside the fragment from the FragmentActivity
which then updated the view.
要做到这一点是有一个公共的方法,例如 updateFragment(数据)
或片段相似,并调用从父<$ C $最简单的方法C> FragmentActivity 。然后片段可以访问它使用自己的布局 this.getView()
The easiest way to do it is to have a public method such as updateFragment(data)
or similar in the Fragment, and call that from the parent FragmentActivity
. The fragment can then access it's own layout using this.getView()
编辑:
因此,对于你code结构的一个例子可能是:
So an example structure for your code might be:
Class FragmentActivity {
method updateFragments() {
Fragment myFrag = fragmentPagerAdapter.getItem(position);
myFrag.updateView("This is my new example string to display on the page");
}
}
Class Fragment {
public method updateView(String newData) {
((TextView) this.getView().findViewById(R.id.text1)).setText(newData);
}
}
这篇关于Viewpager与Android的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!