简体   繁体   中英

android call Fragment from another fragment onclick button

I m beginner to Android. I'm trying to pass value from one fragment to another fragment. But I've found no correct code for that .. so please, can anybody write the correct code for it. I also tried FragmentTransaction, But its not working. So please help me. thank u..

请尝试以下示例,该示例说明了在片段之间传递数据的标准方法http://android-er.blogspot.in/2013/04/handle-onlistitemclick-of-listfragment.html

You can send a Bundle to one Fragment to another Fragment as

fragment.setArguments(BundlObj);

and get them in another fragment as

Bundle b = this.getArguments();

Try out as below to add values in Fragment

FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
TestFragment llf = new TestFragment();
Bundle m_bundle = new Bundle();
m_bundle.putString("Key", <yourValue>);
llf.setArguments(m_bundle);
ft.replace(R.id.fragmentswitcherframe, llf);
ft.commit();

Get the value on another Fragment as below:

m_buBundle = this.getArguments();
String Val = m_buBundle.getString("Key");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM