首页 \ 问答 \ 如何知道Android ActionBar选项卡式活动中哪个选项卡在视图中(How to know which tab is in view in an Android ActionBar Tabbed Activity)

如何知道Android ActionBar选项卡式活动中哪个选项卡在视图中(How to know which tab is in view in an Android ActionBar Tabbed Activity)

所以我使用ViewPager使用ActionBar Tabbed Activity创建了一个Android应用程序项目。 我还创建了两个片段类,并附加了相应的片段布局。 在选择相应的选项卡时,我将片段返回到SectionsPagerAdapter。

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 PlaceholderFragment (defined as a static inner class below).
        switch (position) {
        case 0:
            return new fragmentAddSize();
        case 1:
            return new fragmentMySizes();
    }
    return null;
    }
} 

现在我对此有一些疑问。 我的印象是,每次选择一个选项卡时,它都会调用片段类并进入片段的onCreateView,但它只发生一次。

我想要实现的是知道何时选择选项卡并且相应的片段在视图中。 因此,每当我切换标签时,它只会弹出标签1或标签2中的标签符号。


So I created an Android application project using ActionBar Tabbed Activity using ViewPager. I've also created two fragment classes and attached corresponding fragment layout with them. As the respective tab is selected I return fragment to SectionsPagerAdapter.

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 PlaceholderFragment (defined as a static inner class below).
        switch (position) {
        case 0:
            return new fragmentAddSize();
        case 1:
            return new fragmentMySizes();
    }
    return null;
    }
} 

Now I have some questions about this. I was under the impression that every time a tab is selected, it calls the fragment class and goes into the onCreateView of the fragment but it only happens once.

What I want to achieve is to know when the tabs are selected and the corresponding fragment is in view. So that everytime i switch tabs it just pops a tab sying you are in tab 1 or tab2.


原文:https://stackoverflow.com/questions/26657971
更新时间:2023-04-18 11:04

最满意答案

这种程序集中的CMP通常会将一个值与参数进行比较,并设置一个标志/如果匹配。 然后,如果设置了该标志,JEQ将跳转。

如果你告诉我你的目标处理器是什么,我可以更加精确,甚至使用正确的术语,等等=)


CMP in that sort of assembly will generally compare a value to the argument, /and set a flag/ if it matches. Then JEQ will jump if that flag is set.

If you told me what your target processor is, I could be a lot more precise about it, and even use correct terminology, etc. =)

相关问答

更多
  • 考虑根据您提供的(正确)定义评估简单的foldr表达式: foldr (+) 0 [1,2,3,4] = 1 + foldr (+) 0 [2,3,4] = 1 + 2 + foldr (+) 0 [3,4] = 1 + 2 + 3 + foldr (+) 0 [4] = 1 + 2 + 3 + 4 + foldr (+) 0 [] = 1 + 2 + 3 + 4 + 0 = 10 所以你是对的: acc并不真正“积累”任何东西。 它永远不会取0以外的0 。 如果它不是累加器,它为什么叫做“acc”? ...
  • START: LDA #$11 ; load accumulator - A=$11 STA $2123 ; store accumulator to a memory address - memory[$2123] = $11 CLRA - A=$00 (redundant, as next instruction will load A again) LDA #$67 ; load accumulator - A=$67 ...
  • 这种程序集中的CMP通常会将一个值与参数进行比较,并设置一个标志/如果匹配。 然后,如果设置了该标志,JEQ将跳转。 如果你告诉我你的目标处理器是什么,我可以更加精确,甚至使用正确的术语,等等=) CMP in that sort of assembly will generally compare a value to the argument, /and set a flag/ if it matches. Then JEQ will jump if that flag is set. If you t ...
  • 这个想法是eToPrint是两个事件的结合:当你按下字符时和按下回车键。 这里有一个例子(反应性香蕉0.8): eToPrint = accumE "" $ unions [(:) <$> eWritable, const "" <$> eEnter] 要“保持”它,您可以使用Behavior 。 这是一个完整的解决方案: bString = accumB "" $ unions [(:) <$> eWritable, const "" <$> eEnter] eOut = bString <@ e ...
  • 注意 a≤2⇒a - 2≤0⇒a - 2 <0∨a= 0 可以使用现有说明测试这两种情况。 如果你想实现if (a0 <= a1) ... else ...你可以使用 LODD a0 /Accumulator = a0 SUBD a1 /Accumulator = a0 - a1 jzer _THEN_branch /Jump to "then branch" if a0 == a1 jneg _THEN_branch /Jump to "th ...
  • 这就是.reduce()的用途: var accumulator = _.reduce([1, 2, 3], function(acc, num) { acc[num] = num + 1; return acc; }, {}); 在现代浏览器中,Array原型上的原生.reduce()与lodash和Underscore提供的版本大致相同。 .map() API用于从现有数组创建新数组。 如果你只想对数组的每个元素做一些事情,你可以使用.forEach() 。 .filter() API用于创建数 ...
  • 什么是不使用join的动机? lst = [52.0, 55.0, 567.0, 92.0, 2.0, 5.0] def foo(lst): bar = '' for i in lst: i = format(i, '.2f') bar+= '${}, '.format(str(i)) bar = bar.rstrip(', ') return '{'+bar+'}' print(foo(lst)) Whats the motiviati ...
  • 我添加了一个新的答案,因为我已经修复了这个问题,我刚刚上传到Hackage的pipes-3.3 -3.3。 管道背后的理论表明,您期望的全局行为一直是正确的行为,而WriterP现在表现为全局,因此您可以在管道中折叠。 我修改了你的例子,表明你将使用pipes-3.3实现它pipes-3.3 : import Control.Proxy import Control.Proxy.Trans.Writer main = do let source = enumFromToS (0::Int) 5 ...
  • 是的,您不需要CPU的累加器。 例如,基于堆栈的处理器通常只有一个或两个堆栈指针但没有累加器。 正如文章所说,这些处理器在操作之前加载值以便从内存进行操作。 Yes, you don't need an accumulator for a CPU. For example, stack-based processors typically only have one or two stack pointers but no accumulator. As the article says, these pr ...
  • 不知道你错过了什么/问什么,但让我试一试。 首先,您必须知道流如何工作并在Elixir中表示:流只是一组在可枚举上运行的函数。 当你组成流(例如, 1..3 |> Stream.map(...) |> Stream.map(...) )时,你没有1..3 |> Stream.map(...) |> Stream.map(...)做任何“具体”,你只是将函数添加到将用于处理初始可枚举的函数列表中。 当用流调用Enum.reduce/3时,就是当你开始迭代可枚举时(一次一个元素)。 通过检查Enum.reduc ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)