的Andr​​oid如何根据第一个选项卡输入更新第二个标签? [英] Android how to update 2nd tab according to 1st tab input?

查看:157
本文介绍了的Andr​​oid如何根据第一个选项卡输入更新第二个标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用建2个选项卡片段。第一个选项卡中有一个的EditText 按钮。如果用户输入的东西在的EditText ,然后点击按钮它进入第二个选项卡。 onButtonClick 我已经设置为显示第二选项卡,但我的价值不被更新。虽然我已经成功地写在会议第一标签值。但不知道如何更新第二个标签?如何重建第二个选项卡?

加了我code位置:

在碎裂我onButtonClick我呼吁这个功能:

 私人无效goToFragmentB(字符串1stTabValue)
{
    ViewPager mViewPager =(ViewPager)getActivity()findViewById(R.id.pager)。
       //我的第二个选项卡中有一个TextView,我需要设置1stTabValue。应该是什么code
       //设置1stTabValue在第二个选项卡
    mViewPager.setCurrentItem(1);
}


解决方案

编辑:

标签不会刷新,因为意图将被要求只在第一次。虽然添加的标签,你会设置意图添加这个标志有 addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

例如:

 意向书I =新意图()。setClass(这一点,YourClass.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);


您可以使用共享preferences ,存放在存储preferences输入值,并在第二个选项卡获得

I have build 2 tabs using Fragment. 1st tab has a EditText and a button. If user input something in the EditText and click on the button it goes to 2nd tab. onButtonClick I have set to show 2nd tab but my value is not being updated. Although I have successfully written the 1st tab value in session. But don't know how to update the 2nd tab? How to rebuild the 2nd tab?

Added my code here:

In FragmentA I onButtonClick I have called this function:

private void goToFragmentB(String 1stTabValue)
{
    ViewPager mViewPager = (ViewPager) getActivity().findViewById(R.id.pager);
       // My 2nd tab has a TextView where I need to set the 1stTabValue. What should be the code
       // to set 1stTabValue in 2nd tab
    mViewPager.setCurrentItem(1);
}

解决方案

Edit:

Tab will not refresh because Intent will be called for the first time only.. While adding tabs you will set intent add this flag there addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

Example :

 Intent i = new Intent().setClass(this, YourClass.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);


You Can use Shared Preferences, Store the input values in stored preferences and get in the second Tab

这篇关于的Andr​​oid如何根据第一个选项卡输入更新第二个标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆