logo
Tags down

shadow

Send data from fragment to another fragment


By : Derek
Date : October 16 2020, 08:10 AM
this one helps. 2 solution : -If you back to the fragment (by create new fragment),create a call back like
code :
A extends Fragment(){

public A setMethod(X a){
this.a = a;
  return this;
}
}
new A().setData(yourdata)


Share : facebook icon twitter icon

How to send data from fragment to fragment within same fragment activity?


By : Vijay
Date : March 29 2020, 07:55 AM
help you fix your problem First communicate to the activity that hosts the fragment1 using a interface as a callback. Then you can communicate to fragment2.
You find more info and code snippets @
code :
public class MainActivity extends Activity implements ReturnData{


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        FragmentOne newFragment = new FragmentOne();
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.replace(R.id.container, newFragment);
        transaction.addToBackStack(null);
        transaction.commit();

    }

    @Override
    public void sendData(String result) {
        // TODO Auto-generated method stub
        FragmentTwo newFragment = new FragmentTwo();
        Bundle args = new Bundle();
        args.putString("key",result);
        newFragment.setArguments(args);
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.replace(R.id.container, newFragment);
        transaction.addToBackStack(null);
        transaction.commit();

    }

}
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:id="@+id/container"
    android:layout_height="fill_parent" >

</FrameLayout>
public class FragmentOne extends Fragment {

    public interface ReturnData
    {
        public void sendData(String result);
    }

    ReturnData mCallback;
     @Override
        public void onAttach(Activity activity) {
            super.onAttach(activity);

            // This makes sure that the container activity has implemented
            // the callback interface. If not, it throws an exception
            try {
                mCallback = (ReturnData) activity;
            } catch (ClassCastException e) {
                throw new ClassCastException(activity.toString()
                        + " must implement ReturnData");
            }
        }
    TextView tv2;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.frag1,container,false);
        tv2 = (TextView) rootView.findViewById(R.id.textView2);
        Button b= (Button) rootView.findViewById(R.id.button1);
        b.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                mCallback.sendData(tv2.getText().toString());
            }

        });
        return rootView;
    }   
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="88dp"
        android:text="Button" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="46dp"
        android:text="This is Fragment One" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="82dp"
        android:text="Hello is communicated to Fragment Two on Button Click" />

</RelativeLayout>
public class FragmentTwo extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.frag2,container,false);
        TextView tv1 = (TextView) rootView.findViewById(R.id.textView1);
        String text = getArguments().getString("key");
        tv1.append(text);
        return rootView;
    }   
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="36dp"
        android:text="Display : " />

</RelativeLayout>

Android / Fragment - How do I pass parameters of the Last Fragment and send to Previous Fragment?


By : MatiG
Date : March 29 2020, 07:55 AM
should help you out Your activity can implement a custom listener interface on the Activity and use a reference to it in your fragment to pass the communication back.

Send data from fragment to fragment using Tab Layout with Swipeable Views in Android


By : Shalahuddin Al Ayyub
Date : March 29 2020, 07:55 AM
hop of those help? I created a Tab Layout with Swipeable Views. I'm trying to pass a string from fragment to Fragment Thank you in Advance Details_customer.java , In Cust_Details_address.java I Override the method like this
code :
@Override
public void onStart(){
    super.onStart();

    btnsubmit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
        String firstname = ((EditText)getActivity().findViewById(R.id.fname)).getText().toString();
        Toast.makeText(getActivity().getApplicationContext(),"Hi "+firstname ,Toast.LENGTH_SHORT).show();
        }    });

android - I want to send data from recyclerview adapter from fragment to fragment opening new fragment


By : Alex
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Solution 1:
In the code where you replace HomeDetailFragment, call addToBackStack() like this
code :
fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.frame_fragmenthome, fragmentDetail);
fragmentTransaction.addToBackStack(null);    // add this line to your code
fragmentTransaction.commit();

Android: How to send a string data from one fragment to another fragment of the same main activity?


By : user2035243
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further The data that you want to pass to the fragment(According to your problem you should pass a string instad of int) :
code :
Bundle bundle = new Bundle();
bundle.putInt(key, value);
fragment.setArguments(bundle);
Bundle bundle = this.getArguments();
if (bundle != null) {
    int i = bundle.getInt(key, defaulValue);
}
Related Posts Related Posts :
  • React Native changes to code have no affect on emulator app?
  • Get the TextView value of the gridview while clicking on an element
  • How to launch an intent for a third party app?
  • Going crazy trying to change android theme on Xamarin.Forms
  • Could not find any matches for com.android.tools.build:gradle:2.3.+ as no versions of com.android.tools.build:gradle are
  • How can I capture variables inside of Context
  • React Native : Could not find com.android.tools.build:gradle:2.2.3
  • Google Login/Signin on Yandex Android extension
  • Retrofit generates wrong GET request parameters from Map<String : Any>
  • Flutter app crashing when opening first time with ClassNotFoundException on Android
  • Android LinearLayout programmatically one column left, one column float right
  • Kotlin - convert UTC to local time
  • Android'd ForegroundDispatch for NFC
  • How to use Shared Preferences in class to set all activities?
  • Synchronous Volley request locks up
  • How do I inherit a function from another class into an activity in kotlin?
  • BottomAppBar Navigation Icon with Badge
  • Change content_main XML in Basic Navigation Drawer Template
  • HERE SDK Android: PositioningManager not working with NETWORK_PROVIDER in 3.8 or 3.9
  • No response after putting in Header in request
  • Where are default shared preferences written to?
  • how to show a part of next image in daimajia slider?
  • AlertDialog Builder inside holder.itemView.setOnClickListener onBindViewHolder
  • Flutter Grid view is not scrolling
  • How to access view in addTextChangedListener?
  • How do I link multiple activities in android navigation editor?
  • Failed to resolve: com.google.android.exoplayer:extension-mediasession:2.8.4
  • ViewPager + Picasso + multiple images from URL String array
  • how do I open another fragment after selecting the image in recycler view?
  • Custom TitleView with Description and Preview Image Android TV (FireTV)
  • Gradle project sync failed. basic functionality (e.g. editing debugging) will not work properly
  • how to retrieve firebase storage images in release mode?
  • Android Studio: Could not find matches as no versions of com.android.tools.build:gradle are available
  • Getting a JSON Left side Value
  • Is it possible to use of Mobile data while transferring file via Wi-Fi Direct?
  • Build Error: Could not find any version that matches com.android.tools.build:transform-api:1.5.+
  • Robolectric 4.0.2 test are not running in gradle 3.2.1 with NoSuchMethodError: setUseLegacyResources(Z)V
  • How to be notified of another app's crash?
  • Could not find com.android.tools.build:gradle:2.2.3
  • Recyclerview scroll to empty Edit Text
  • How to set applicationID using Android.mk
  • Firebase: How to implement "take action only when another device is online"?
  • Can not find attribute app:useSimpleSummaryProvider
  • Relation between buffers and glVertexAttribPointer
  • Android - focus navigation back button
  • Disable WiFi option in Google Text To Speech (TTS) programmatically
  • using AdapterViewFlipper in a fragment in order to create image slider
  • How to add animation before the opening of a new activity?
  • Integrating Google Calendar API
  • Have the WebView still play the video while in background
  • Publishing beta version of an app as Production version
  • How do I clear out my data on app signout from crashlytics
  • Circular dependency between the following tasks while using firebase Crashlytics
  • Is it possible to get the link of uploaded file from google drive API
  • Calling 'insert' in a room database does not complete the transaction
  • Android NDK C++ breakpoints only work on emulator
  • Android Beacon Library not seeing any beacons
  • Do I need to save my old project after I change the version name?
  • Change boolean variable if TRY code is executed correctly
  • How to detect android.permission.USE_SIP
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org