- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试在应用程序中使用 Tabs + Swipe,并希望使用 ADT 在创建 Activity 时为我提供的导航类型“Fixed Tabs + Swipe”。
现在 ADT 吐出漂亮的代码,我稍微修改了一下...
我完全理解代码以及发生了什么......但是我如何才能教应用程序使用我的三个 fragment 而不是愚蠢的虚拟 fragment ? :(
我找不到任何处理 ADT“导航类型”的教程...
感谢您的帮助!
public class MainActivity extends FragmentActivity implements ActionBar.TabListener {
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Set up the action bar.
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Create the adapter that will return a fragment for each of the three
// primary sections of the app.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
// When swiping between different sections, select the corresponding
// tab. We can also use ActionBar.Tab#select() to do this if we have
// a reference to the Tab.
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
//Adding Tabs
actionBar.addTab(actionBar.newTab().setText("Tab 1").setTabListener(this));
actionBar.addTab(actionBar.newTab().setText("Tab 2").setTabListener(this));
actionBar.addTab(actionBar.newTab().setText("Tab 3").setTabListener(this));
}
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
// When the given tab is selected, switch to the corresponding page in
// the ViewPager.
mViewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(ActionBar.Tab tab,FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabReselected(ActionBar.Tab tab,FragmentTransaction fragmentTransaction) {
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a DummySectionFragment (defined as a static inner class
// below) with the page number as its lone argument.
Fragment fragment = new DummySectionFragment();
Bundle args = new Bundle();
args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
fragment.setArguments(args);
return fragment;
}
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
}
public static class DummySectionFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
public static final String ARG_SECTION_NUMBER = "section_number";
public DummySectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main_dummy,container, false);
TextView dummyTextView = (TextView) rootView.findViewById(R.id.section_label);
dummyTextView.setText(Integer.toString(getArguments().getInt(ARG_SECTION_NUMBER)));
return rootView;
}
}
}
最佳答案
设置 fragment 的 switch-case 很简单,而且非常清楚。让你的每个 fragment 在你的 xml 中膨胀 Root View
@Override
public Fragment getItem(int index) {
Fragment fragment = null;
switch(index){
case 0:
fragment = new Fragment1();
break;
case 1:
fragment = new Fragment2();
break;
case 2:
fragment = new Fragment3();
break;
default:
break;
}
//set args if necessary (which it isn't?)
Bundle args = new Bundle();
args.putInt(ObjectFragment.ARG_OBJECT, index + 1);
fragment.setArguments(args);
//return fragment
return fragment;
}
关于安卓: "Navigation Type: Fixed Tabs + Swipe",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15591087/
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 3年前关闭。 Improve thi
有人知道可以在线使用 FIX 实用程序来验证修复消息吗?即:接受修复消息并检查诸如正文长度和校验和之类的内容。谢谢 最佳答案 https://fixspec.com 上有一个修复日志解码器.当您输入一
在FIX服务器上发送订单请求并更改标签的顺序。 如果我想要输出由我安排的序列(而不是被服务器修改)。 public void send50(Order order) { quickfix.fi
我正在用 C++ 构建一个 FIX 引擎,但我没有引用来了解什么是好的性能数字。考虑到网络时间和 FIX 解析时间,客户端向服务器发送 FIX 消息的最佳时间(以微秒为单位)是多少?还有人知道这个简单
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求提供代码的问题必须表现出对所解决问题的最低限度理解。包括尝试过的解决方案、为什么它们不起作用,以及
我不明白为什么我的固定背景开始出现,因为它有时没有被固定。 这是一个非常特殊的案例,我知道如何解决它。 您可以删除: .row2 position:relative 或 row1 div -webki
我看过三列的例子(fixed fluid fixed)。但是,我需要一个四列解决方案的示例。 两个外部列是固定的。两个内柱是流动的。 固定 |流体 |流体 |固定 最佳答案 您可以使用 calc .
我试图说服自己输入 Fix和功能 fix是一回事。 但我找不到他们的定义之间的相关性 -- definition of fix fix :: (p -> p) -> p fix f = let {x
这是我已经在这里提出的另一个问题的后续How can I play a single tone or custom wave with Delphi? 长话短说,我使用 MMSystem 的 wave
刚刚完成一个站点并遇到位置问题:已在 IE7 上修复。我用谷歌搜索并尝试了不同的 Doctypes,但固定区域在 IE7 上仍然不在位。 我没有 IE7,但一位客户员工有,我可以使用在线 IE 渲染器
我有我的 设置为 background-attachment: fixed但这留下了我的标签正常滚动。如果我设置 position: fixed到我的标签,它们会跳转到页面顶部。有什么办法可以做与 b
我有一个包含标题页(导航栏)的 php 页面。我想将导航栏显示为固定标题,但每当将其位置更改为固定时,它都会删除滚动条(水平和垂直)并且我无法滚动页面。如果我想保持我的标题固定并且我不想固定位置。我怎
已结束。此问题不符合 Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是无关紧要的,
我正在使用 jquery mobile,对于页眉/页脚,我使用的是 data-position="fixed"。 但是,当我们滚动页面时......页眉页脚消失并在滚动停止时重新出现.. 有没有一种方
我正在尝试连接到使用 FIX 5.0 的代理 我想利用 quickfixj以方便和快速地实现。 这行吗?我假设 5.0 extends(可以这么说)以前版本的功能,但我不想走得太远,结果导致更多问题,
如何放置 position:fixed内容在页面背景中的容器,而其他内容在其上滚动,同时仍然保持点击背景元素的能力? 效果类似于前景内容在固定背景上滚动的视差滚动情况,但我希望能够将 HTML 放在背
我尝试将 z-index 设置为 body 下的某些位置为 fixed 的元素 示例如下: HTML menu content ....
我花了几个小时寻找这个问题的答案,但其他人提供解决方案的场景似乎比我的稍微简单一些。 有没有办法在固定大小的 div 中放置一个 position:fixed 元素,而该元素不会溢出 div? 换句话
此问题已在 SO 和其他地方多次报告,但我找不到任何有效的解决方案。 如果您有固定位置的 div 和固定附加的背景,在某些特定情况下,在 Google Chrome 上呈现会出现错误(在 Firefo
我想在我网站的页面顶部创建一个标题栏,但我在布局方面遇到了问题。以下是我想要的结果: goal http://ambiguities.ca/images/goal.png 这是 html:
我是一名优秀的程序员,十分优秀!