ITKeyword,专注技术干货聚合推荐

注册 | 登录

android - Fragments within a Fragment cannot retain their values

itPublisher 分享于

2021腾讯云限时秒杀,爆款1核2G云服务器298元/3年!(领取2860元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1062

2021阿里云最低价产品入口+领取代金券(老用户3折起),
入口地址https://www.aliyun.com/minisite/goods

推荐:android Fragments:管理fragment

要管理fragment们,需使用FragmentManager,要获取它,需在activity中调用方法getFragmentManager()。 你可以用FragmentManager来做以上事情:   1使用方法findF

I have an activity and in that activity I have 2 Fragments A and B.

Fragment A has a EditText for entering Email.

Fragment B contains 2 more fragments B1 and B2 which can be selected using two buttons at the bottom of Fragment B.

B1 and B2 contain an EditText for entering Name and Number.

When i enter Email, Name and Number and switch between fragments A and B, Email value retains BUT the Name and Number values in sub-fragments B1 and B2 gets lost.

Is it because i have nested fragments in B?

How can i retain the values of sub-fragments B1 and B2?

推荐:android Fragments详解二:创建Fragment .

http://blog.csdn.net/nkmnkm/article/details/7169323 创建Fragment     要创建fragment,必须从Fragment或Fragment的派生类派生出一个类。Fragment的代码写起

I am new to android, Can anybody refer a good working example?

android android-activity android-fragments android-savedstate
|
  this question
asked Mar 11 '15 at 13:10 Kazmi 218 1 3 15      This might be relevant: stackoverflow.com/questions/20550016/… –  mach Mar 11 '15 at 13:14

 | 

1 Answers
1

It's always a pain working with 2+ fragments.

Not the best workaround: Try using SharedPreferences to save and display Name and Number, and reload the entire activity when needed so that changes get effected.


|
  this answer
answered Mar 11 '15 at 13:33 Sajith Sageer 56 6      As i am new with android so I was testing it with the text fields .... In reality i will displaying 2 different ListViews in Fragments A and B. And i don't want my list views to loose the values. –  Kazmi Mar 16 '15 at 14:05      Are you using tabs to switch between fragments? –  Sajith Sageer Mar 16 '15 at 17:50      I am selecting Fragment A and B from a menu which slides in from left, and Fragment B has two button at the bottom with which you can switch between sub-fragments B1 and B2. –  Kazmi Mar 19 '15 at 10:03      i have found 2 solutions but don't know which one is efficient so would like your suggestions, please see the link, i appreciate your help so far. stackoverflow.com/questions/29275746/… –  Kazmi Mar 26 '15 at 10:10      In my project I used 'replace' a lot, to change fragments and ended up having many problems. So I would say go with the first solution. –  Sajith Sageer Mar 28 '15 at 9:59  |  show more comment

推荐:android Fragments详解四:管理fragment

要管理fragment们,需使用FragmentManager,要获取它,需在activity中调用方法getFragmentManager()。 你可以用FragmentManager来做以上事情: 1使用方法findFra


相关阅读排行


相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。