1

I have activity and activity has a viewpager.

  • I want to send my edittext's text to pager 1 and call page1's asynctask from activity has viewpager.

    Here is image

Zoe
  • 27,060
  • 21
  • 118
  • 148
  • My personally, you have to get the fragment of page 1. In this fragment, you create a method with public scope so that the activity is able to call it. To get fragment from `ViewPager` you can visit here: https://stackoverflow.com/questions/18609261/getting-the-current-fragment-instance-in-the-viewpager (if the result is null you should consider that the fragment is created or not) – John Le Nov 25 '17 at 03:11
  • I solved, i used edittext in fragment. – Emin Kişi Nov 28 '17 at 11:46

1 Answers1

0

in case you want to send text from outside ViewPager (Activity) to somewhat screen inside ViewPager,

try implement this in activity, to provide the way to get your text from this activity through interface

public class TestActivity implement GetTextCallback {
   public interface GetTextCallback {
       String getText()
   }

   @Override
   public String getText() {
       return editText.getText().toString();
   }
}

and this in ViewPager's fragment, to get text from your activity through interface you created

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    if (getTextCallback == null) {
        getTextCallback = (GetTextCallback) activity;
    }
}

public void whenYouWantToGetText() {
    if (getTextCallback != null) {
        getTextCallback.getTextYouWant();
    } 
}
JiratPasuksmit
  • 672
  • 7
  • 18