Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9185517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:17:48+00:00 2026-06-17T19:17:48+00:00

I have a little problem which is sending information from one fragment to another

  • 0

I have a little problem which is sending information from one fragment to another fragment. I created a project with swipe navigation. In one fragment I have only a button. In the other fragment there is only a textview. I want to send a text to fragment2 when I click the button in fragment1. I tried it with interfaces, but I don’t know what I am doing wrong.

Here are the current codes.

The interfaces:

public interface ActivityCommunicator {

    public void passDataToActivity(String someValue);

}


public interface FragmentCommunicator {

    public void passDataToFragment(String someValue);

}

The MainActivity:

public class MainActivity extends FragmentActivity implements ActivityCommunicator {

public FragmentCommunicator fragmentCommunicator;
SectionsPagerAdapter mSectionsPagerAdapter;
Button btn;
ViewPager mViewPager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    btn = (Button)findViewById(R.id.button1);
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
}

private void SendText(View v) {

    if(fragmentCommunicator != null) {

        fragmentCommunicator.passDataToFragment("Hi from FragmentActivity");
    }
}

@Override
public void passDataToActivity(String someValue) {
    // TODO Auto-generated method stub
}
}

Fragment1:

public class Fragment1 extends Fragment {

Button btn;

public Fragment1(int position) {
    // TODO Auto-generated constructor stub
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragmen1, container, false);
    btn = (Button)v.findViewById(R.id.button1);
    return v;
}
}

Fragment2:

public class Fragment2 extends Fragment implements FragmentCommunicator {

TextView tv;
private ActivityCommunicator activityCommunicator;
private String activityAssignedValue ="";

public Fragment2(int position) {
    // TODO Auto-generated constructor stub
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragment2, container, false);
    tv = (TextView)v.findViewById(R.id.textView1);
    return v;
}

@Override
public void passDataToFragment(String someValue) {
    activityAssignedValue = someValue;
    tv.setText(someValue); 
}
}

fragment1.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="SendText"
    android:text="Button" />

</LinearLayout>

fragment2.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

main.xml:

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<!--
This title strip will display the currently visible page title, as well as the page
titles for adjacent pages.
-->

<android.support.v4.view.PagerTitleStrip
    android:id="@+id/pager_title_strip"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:background="#33b5e5"
    android:paddingBottom="4dp"
    android:paddingTop="4dp"
    android:textColor="#fff" />

</android.support.v4.view.ViewPager>

The logcat error message:

01-24 14:13:41.750: W/dalvikvm(1576): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
01-24 14:13:41.760: E/AndroidRuntime(1576): FATAL EXCEPTION: main
01-24 14:13:41.760: E/AndroidRuntime(1576): java.lang.IllegalStateException: Could not find a method SendText(View) in the activity class com.example.zz.MainActivity for onClick handler on view class android.widget.Button with id 'button1'
01-24 14:13:41.760: E/AndroidRuntime(1576):     at android.view.View$1.onClick(View.java:3578)
01-24 14:13:41.760: E/AndroidRuntime(1576):     at android.view.View.performClick(View.java:4084)
01-24 14:13:41.760: E/AndroidRuntime(1576):     at  android.view.View$PerformClick.run(View.java:16966)
01-24 14:13:41.760: E/AndroidRuntime(1576):     at android.os.Handler.handleCallback(Handler.java:615)
01-24 14:13:41.760: E/AndroidRuntime(1576):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-24 14:13:41.760: E/AndroidRuntime(1576):     at android.os.Looper.loop(Looper.java:137)
01-24 14:13:41.760: E/AndroidRuntime(1576):     at android.app.ActivityThread.main(ActivityThread.java:4745)
01-24 14:13:41.760: E/AndroidRuntime(1576):     at java.lang.reflect.Method.invokeNative(Native Method)
01-24 14:13:41.760: E/AndroidRuntime(1576):     at java.lang.reflect.Method.invoke(Method.java:511)
01-24 14:13:41.760: E/AndroidRuntime(1576):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-24 14:13:41.760: E/AndroidRuntime(1576):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-24 14:13:41.760: E/AndroidRuntime(1576):     at dalvik.system.NativeStart.main(Native Method)
01-24 14:13:41.760: E/AndroidRuntime(1576): Caused by: java.lang.NoSuchMethodException: SendText [class android.view.View]
01-24 14:13:41.760: E/AndroidRuntime(1576):     at java.lang.Class.getConstructorOrMethod(Class.java:460)
01-24 14:13:41.760: E/AndroidRuntime(1576):     at java.lang.Class.getMethod(Class.java:915)
01-24 14:13:41.760: E/AndroidRuntime(1576):     at android.view.View$1.onClick(View.java:3571)
01-24 14:13:41.760: E/AndroidRuntime(1576):     ... 11 more

Any advices to fix that? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:17:49+00:00Added an answer on June 17, 2026 at 7:17 pm

    Could we see your onClickListener for your button? It seems that it is calling the private method sendText of your MainActivity

    edit: you did it in your XML file, my bad 😀 But I still think that the fact that the SendText method is private could be the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little problem with sending an extra from one activity to another.
I have a little problem sending the right id to another activity as extra.I'm
I have this little problem, that I cannot figure out which arguments to pass
I'm with a little problem. I have the container div for some elements which
Hi I have a little problem. Is there a way to identify which skin
I have a little problem. I've got json datas from a $.get() request with
I have a little problem, which I can't solve.. Well, I built a BaseActivity.cs
I have a little problem. I have a form, which is my login form.
Hello folkes I have this little problem for which I cannot find a suitable
I have a little problem with a FileReference which I use to let users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.