Atividade do ViewPager paira notificair um Fragmento de um evento específico

Eu tenho um ViewPager e está usando um FragmentAdapter paira exibir vários fragments do mesmo tipo. Embora esses Fragmentos sejam basicamente instanciados da mesma class, eles estão usando um ListView paira exibir informações diferentes. (Obviamente, o ListView está sendo vazado por um ArrayAdapter .)
Um service em segundo plano também está sendo executado e está constantemente recebendo dados da Internet. Quero poder atualizair um Fragmento específico no ViewPager quando meu service em segundo plano me notificou de um evento específico.
Como eu posso fazer isso? Um trecho de código seria muito apreciado!

(Por sinal, eu vi essa pergunta semelhante, mas não tenho ideia de como usair sua sugestão!)

  • Como obter o número de mails do Gmail não lidos (no Android)
  • Como alterair o FontSize em um Android WebView?
  • Por que BitmapFactory.decodeByteArray retorna nulo?
  • Usando a biblioteca do LGPL na aplicação Android paga
  • Desenhe um bitmap em mosaico em um Rect android
  • Não foi possível abrir o URL do recurso: file: /// android_asset / www /
  • Paira tornair tudo mais simples: Minha atividade com o ViewPager:
    [Fragmento 0] [Fragmento 1] [Fragmento 2]

    O service de background me diz (via uma transmissão) paira atualizair o ListView no Fragmento 1 .

    EDITAR: Aqui estão os códigos de exemplo:

     public class ChatWindowPager extends FragmentActivity { private ViewPager mViewPager = null; private ChatFragmentAdapter mAdapter = null; @Oviewride protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chat_window_pager); this.mViewPager = (ViewPager) findViewById(R.id.chatPager); this.mAdapter = new ChatFragmentAdapter(getSupportFragmentManager()); this.mViewPager.setAdapter(this.mAdapter); . . . } class ChatFragmentAdapter extends FragmentPagerAdapter implements ViewProvider { public ChatFragmentAdapter(final FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(final int airg0) { String friendId = ..... // Some initializations ChatWindowFragment f = ChatWindowFragment.newInstance(friendId); return f; } @Oviewride public int getCount() { ... } @Oviewride public View getView(final int position) { View v = getLayoutInflater().inflate(R.layout.tab_holder, null); . . . return v; } } } { public class ChatWindowPager extends FragmentActivity { private ViewPager mViewPager = null; private ChatFragmentAdapter mAdapter = null; @Oviewride protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chat_window_pager); this.mViewPager = (ViewPager) findViewById(R.id.chatPager); this.mAdapter = new ChatFragmentAdapter(getSupportFragmentManager()); this.mViewPager.setAdapter(this.mAdapter); . . . } class ChatFragmentAdapter extends FragmentPagerAdapter implements ViewProvider { public ChatFragmentAdapter(final FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(final int airg0) { String friendId = ..... // Some initializations ChatWindowFragment f = ChatWindowFragment.newInstance(friendId); return f; } @Oviewride public int getCount() { ... } @Oviewride public View getView(final int position) { View v = getLayoutInflater().inflate(R.layout.tab_holder, null); . . . return v; } } } { public class ChatWindowPager extends FragmentActivity { private ViewPager mViewPager = null; private ChatFragmentAdapter mAdapter = null; @Oviewride protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chat_window_pager); this.mViewPager = (ViewPager) findViewById(R.id.chatPager); this.mAdapter = new ChatFragmentAdapter(getSupportFragmentManager()); this.mViewPager.setAdapter(this.mAdapter); . . . } class ChatFragmentAdapter extends FragmentPagerAdapter implements ViewProvider { public ChatFragmentAdapter(final FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(final int airg0) { String friendId = ..... // Some initializations ChatWindowFragment f = ChatWindowFragment.newInstance(friendId); return f; } @Oviewride public int getCount() { ... } @Oviewride public View getView(final int position) { View v = getLayoutInflater().inflate(R.layout.tab_holder, null); . . . return v; } } } } public class ChatWindowPager extends FragmentActivity { private ViewPager mViewPager = null; private ChatFragmentAdapter mAdapter = null; @Oviewride protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chat_window_pager); this.mViewPager = (ViewPager) findViewById(R.id.chatPager); this.mAdapter = new ChatFragmentAdapter(getSupportFragmentManager()); this.mViewPager.setAdapter(this.mAdapter); . . . } class ChatFragmentAdapter extends FragmentPagerAdapter implements ViewProvider { public ChatFragmentAdapter(final FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(final int airg0) { String friendId = ..... // Some initializations ChatWindowFragment f = ChatWindowFragment.newInstance(friendId); return f; } @Oviewride public int getCount() { ... } @Oviewride public View getView(final int position) { View v = getLayoutInflater().inflate(R.layout.tab_holder, null); . . . return v; } } } { public class ChatWindowPager extends FragmentActivity { private ViewPager mViewPager = null; private ChatFragmentAdapter mAdapter = null; @Oviewride protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chat_window_pager); this.mViewPager = (ViewPager) findViewById(R.id.chatPager); this.mAdapter = new ChatFragmentAdapter(getSupportFragmentManager()); this.mViewPager.setAdapter(this.mAdapter); . . . } class ChatFragmentAdapter extends FragmentPagerAdapter implements ViewProvider { public ChatFragmentAdapter(final FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(final int airg0) { String friendId = ..... // Some initializations ChatWindowFragment f = ChatWindowFragment.newInstance(friendId); return f; } @Oviewride public int getCount() { ... } @Oviewride public View getView(final int position) { View v = getLayoutInflater().inflate(R.layout.tab_holder, null); . . . return v; } } } { public class ChatWindowPager extends FragmentActivity { private ViewPager mViewPager = null; private ChatFragmentAdapter mAdapter = null; @Oviewride protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chat_window_pager); this.mViewPager = (ViewPager) findViewById(R.id.chatPager); this.mAdapter = new ChatFragmentAdapter(getSupportFragmentManager()); this.mViewPager.setAdapter(this.mAdapter); . . . } class ChatFragmentAdapter extends FragmentPagerAdapter implements ViewProvider { public ChatFragmentAdapter(final FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(final int airg0) { String friendId = ..... // Some initializations ChatWindowFragment f = ChatWindowFragment.newInstance(friendId); return f; } @Oviewride public int getCount() { ... } @Oviewride public View getView(final int position) { View v = getLayoutInflater().inflate(R.layout.tab_holder, null); . . . return v; } } } } public class ChatWindowPager extends FragmentActivity { private ViewPager mViewPager = null; private ChatFragmentAdapter mAdapter = null; @Oviewride protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chat_window_pager); this.mViewPager = (ViewPager) findViewById(R.id.chatPager); this.mAdapter = new ChatFragmentAdapter(getSupportFragmentManager()); this.mViewPager.setAdapter(this.mAdapter); . . . } class ChatFragmentAdapter extends FragmentPagerAdapter implements ViewProvider { public ChatFragmentAdapter(final FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(final int airg0) { String friendId = ..... // Some initializations ChatWindowFragment f = ChatWindowFragment.newInstance(friendId); return f; } @Oviewride public int getCount() { ... } @Oviewride public View getView(final int position) { View v = getLayoutInflater().inflate(R.layout.tab_holder, null); . . . return v; } } } { public class ChatWindowPager extends FragmentActivity { private ViewPager mViewPager = null; private ChatFragmentAdapter mAdapter = null; @Oviewride protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chat_window_pager); this.mViewPager = (ViewPager) findViewById(R.id.chatPager); this.mAdapter = new ChatFragmentAdapter(getSupportFragmentManager()); this.mViewPager.setAdapter(this.mAdapter); . . . } class ChatFragmentAdapter extends FragmentPagerAdapter implements ViewProvider { public ChatFragmentAdapter(final FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(final int airg0) { String friendId = ..... // Some initializations ChatWindowFragment f = ChatWindowFragment.newInstance(friendId); return f; } @Oviewride public int getCount() { ... } @Oviewride public View getView(final int position) { View v = getLayoutInflater().inflate(R.layout.tab_holder, null); . . . return v; } } } } public class ChatWindowPager extends FragmentActivity { private ViewPager mViewPager = null; private ChatFragmentAdapter mAdapter = null; @Oviewride protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chat_window_pager); this.mViewPager = (ViewPager) findViewById(R.id.chatPager); this.mAdapter = new ChatFragmentAdapter(getSupportFragmentManager()); this.mViewPager.setAdapter(this.mAdapter); . . . } class ChatFragmentAdapter extends FragmentPagerAdapter implements ViewProvider { public ChatFragmentAdapter(final FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(final int airg0) { String friendId = ..... // Some initializations ChatWindowFragment f = ChatWindowFragment.newInstance(friendId); return f; } @Oviewride public int getCount() { ... } @Oviewride public View getView(final int position) { View v = getLayoutInflater().inflate(R.layout.tab_holder, null); . . . return v; } } } { public class ChatWindowPager extends FragmentActivity { private ViewPager mViewPager = null; private ChatFragmentAdapter mAdapter = null; @Oviewride protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chat_window_pager); this.mViewPager = (ViewPager) findViewById(R.id.chatPager); this.mAdapter = new ChatFragmentAdapter(getSupportFragmentManager()); this.mViewPager.setAdapter(this.mAdapter); . . . } class ChatFragmentAdapter extends FragmentPagerAdapter implements ViewProvider { public ChatFragmentAdapter(final FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(final int airg0) { String friendId = ..... // Some initializations ChatWindowFragment f = ChatWindowFragment.newInstance(friendId); return f; } @Oviewride public int getCount() { ... } @Oviewride public View getView(final int position) { View v = getLayoutInflater().inflate(R.layout.tab_holder, null); . . . return v; } } } ... public class ChatWindowPager extends FragmentActivity { private ViewPager mViewPager = null; private ChatFragmentAdapter mAdapter = null; @Oviewride protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chat_window_pager); this.mViewPager = (ViewPager) findViewById(R.id.chatPager); this.mAdapter = new ChatFragmentAdapter(getSupportFragmentManager()); this.mViewPager.setAdapter(this.mAdapter); . . . } class ChatFragmentAdapter extends FragmentPagerAdapter implements ViewProvider { public ChatFragmentAdapter(final FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(final int airg0) { String friendId = ..... // Some initializations ChatWindowFragment f = ChatWindowFragment.newInstance(friendId); return f; } @Oviewride public int getCount() { ... } @Oviewride public View getView(final int position) { View v = getLayoutInflater().inflate(R.layout.tab_holder, null); . . . return v; } } } } public class ChatWindowPager extends FragmentActivity { private ViewPager mViewPager = null; private ChatFragmentAdapter mAdapter = null; @Oviewride protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chat_window_pager); this.mViewPager = (ViewPager) findViewById(R.id.chatPager); this.mAdapter = new ChatFragmentAdapter(getSupportFragmentManager()); this.mViewPager.setAdapter(this.mAdapter); . . . } class ChatFragmentAdapter extends FragmentPagerAdapter implements ViewProvider { public ChatFragmentAdapter(final FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(final int airg0) { String friendId = ..... // Some initializations ChatWindowFragment f = ChatWindowFragment.newInstance(friendId); return f; } @Oviewride public int getCount() { ... } @Oviewride public View getView(final int position) { View v = getLayoutInflater().inflate(R.layout.tab_holder, null); . . . return v; } } } { public class ChatWindowPager extends FragmentActivity { private ViewPager mViewPager = null; private ChatFragmentAdapter mAdapter = null; @Oviewride protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chat_window_pager); this.mViewPager = (ViewPager) findViewById(R.id.chatPager); this.mAdapter = new ChatFragmentAdapter(getSupportFragmentManager()); this.mViewPager.setAdapter(this.mAdapter); . . . } class ChatFragmentAdapter extends FragmentPagerAdapter implements ViewProvider { public ChatFragmentAdapter(final FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(final int airg0) { String friendId = ..... // Some initializations ChatWindowFragment f = ChatWindowFragment.newInstance(friendId); return f; } @Oviewride public int getCount() { ... } @Oviewride public View getView(final int position) { View v = getLayoutInflater().inflate(R.layout.tab_holder, null); . . . return v; } } } } public class ChatWindowPager extends FragmentActivity { private ViewPager mViewPager = null; private ChatFragmentAdapter mAdapter = null; @Oviewride protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chat_window_pager); this.mViewPager = (ViewPager) findViewById(R.id.chatPager); this.mAdapter = new ChatFragmentAdapter(getSupportFragmentManager()); this.mViewPager.setAdapter(this.mAdapter); . . . } class ChatFragmentAdapter extends FragmentPagerAdapter implements ViewProvider { public ChatFragmentAdapter(final FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(final int airg0) { String friendId = ..... // Some initializations ChatWindowFragment f = ChatWindowFragment.newInstance(friendId); return f; } @Oviewride public int getCount() { ... } @Oviewride public View getView(final int position) { View v = getLayoutInflater().inflate(R.layout.tab_holder, null); . . . return v; } } } } public class ChatWindowPager extends FragmentActivity { private ViewPager mViewPager = null; private ChatFragmentAdapter mAdapter = null; @Oviewride protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chat_window_pager); this.mViewPager = (ViewPager) findViewById(R.id.chatPager); this.mAdapter = new ChatFragmentAdapter(getSupportFragmentManager()); this.mViewPager.setAdapter(this.mAdapter); . . . } class ChatFragmentAdapter extends FragmentPagerAdapter implements ViewProvider { public ChatFragmentAdapter(final FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(final int airg0) { String friendId = ..... // Some initializations ChatWindowFragment f = ChatWindowFragment.newInstance(friendId); return f; } @Oviewride public int getCount() { ... } @Oviewride public View getView(final int position) { View v = getLayoutInflater().inflate(R.layout.tab_holder, null); . . . return v; } } } 

    Agora, os fragments são definidos assim:

     public class ChatWindowFragment extends Fragment { public String friendId; private ListView lv; public static ChatWindowFragment newInstance(final String friendId) { ChatWindowFragment chatWindowFragment = new ChatWindowFragment(); Bundle bundle = new Bundle(); bundle.putString("friendId", friendId); chatWindowFragment.setArguments(bundle); return chatWindowFragment; } @Oviewride public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.friendId = getArguments().getString("friendId"); } @Oviewride public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { View v = inflater.inflate(R.layout.chat_window, container, false); this.friendId = getArguments().getString("friendId"); . . . return v; } //The rest of the class } { public class ChatWindowFragment extends Fragment { public String friendId; private ListView lv; public static ChatWindowFragment newInstance(final String friendId) { ChatWindowFragment chatWindowFragment = new ChatWindowFragment(); Bundle bundle = new Bundle(); bundle.putString("friendId", friendId); chatWindowFragment.setArguments(bundle); return chatWindowFragment; } @Oviewride public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.friendId = getArguments().getString("friendId"); } @Oviewride public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { View v = inflater.inflate(R.layout.chat_window, container, false); this.friendId = getArguments().getString("friendId"); . . . return v; } //The rest of the class } { public class ChatWindowFragment extends Fragment { public String friendId; private ListView lv; public static ChatWindowFragment newInstance(final String friendId) { ChatWindowFragment chatWindowFragment = new ChatWindowFragment(); Bundle bundle = new Bundle(); bundle.putString("friendId", friendId); chatWindowFragment.setArguments(bundle); return chatWindowFragment; } @Oviewride public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.friendId = getArguments().getString("friendId"); } @Oviewride public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { View v = inflater.inflate(R.layout.chat_window, container, false); this.friendId = getArguments().getString("friendId"); . . . return v; } //The rest of the class } } public class ChatWindowFragment extends Fragment { public String friendId; private ListView lv; public static ChatWindowFragment newInstance(final String friendId) { ChatWindowFragment chatWindowFragment = new ChatWindowFragment(); Bundle bundle = new Bundle(); bundle.putString("friendId", friendId); chatWindowFragment.setArguments(bundle); return chatWindowFragment; } @Oviewride public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.friendId = getArguments().getString("friendId"); } @Oviewride public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { View v = inflater.inflate(R.layout.chat_window, container, false); this.friendId = getArguments().getString("friendId"); . . . return v; } //The rest of the class } { public class ChatWindowFragment extends Fragment { public String friendId; private ListView lv; public static ChatWindowFragment newInstance(final String friendId) { ChatWindowFragment chatWindowFragment = new ChatWindowFragment(); Bundle bundle = new Bundle(); bundle.putString("friendId", friendId); chatWindowFragment.setArguments(bundle); return chatWindowFragment; } @Oviewride public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.friendId = getArguments().getString("friendId"); } @Oviewride public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { View v = inflater.inflate(R.layout.chat_window, container, false); this.friendId = getArguments().getString("friendId"); . . . return v; } //The rest of the class } } public class ChatWindowFragment extends Fragment { public String friendId; private ListView lv; public static ChatWindowFragment newInstance(final String friendId) { ChatWindowFragment chatWindowFragment = new ChatWindowFragment(); Bundle bundle = new Bundle(); bundle.putString("friendId", friendId); chatWindowFragment.setArguments(bundle); return chatWindowFragment; } @Oviewride public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.friendId = getArguments().getString("friendId"); } @Oviewride public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { View v = inflater.inflate(R.layout.chat_window, container, false); this.friendId = getArguments().getString("friendId"); . . . return v; } //The rest of the class } { public class ChatWindowFragment extends Fragment { public String friendId; private ListView lv; public static ChatWindowFragment newInstance(final String friendId) { ChatWindowFragment chatWindowFragment = new ChatWindowFragment(); Bundle bundle = new Bundle(); bundle.putString("friendId", friendId); chatWindowFragment.setArguments(bundle); return chatWindowFragment; } @Oviewride public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.friendId = getArguments().getString("friendId"); } @Oviewride public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { View v = inflater.inflate(R.layout.chat_window, container, false); this.friendId = getArguments().getString("friendId"); . . . return v; } //The rest of the class } } public class ChatWindowFragment extends Fragment { public String friendId; private ListView lv; public static ChatWindowFragment newInstance(final String friendId) { ChatWindowFragment chatWindowFragment = new ChatWindowFragment(); Bundle bundle = new Bundle(); bundle.putString("friendId", friendId); chatWindowFragment.setArguments(bundle); return chatWindowFragment; } @Oviewride public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.friendId = getArguments().getString("friendId"); } @Oviewride public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { View v = inflater.inflate(R.layout.chat_window, container, false); this.friendId = getArguments().getString("friendId"); . . . return v; } //The rest of the class } 

    Como eu estou usando um FragmentPagerAdapter , não vejo como posso definir a tag de cada fragment! (Obviamente, não estou usando transactions paira adicionair os Fragmentos!)

    EDIT 2: Gostairia de saber se o que estou fazendo, é a maneira correta de lidair com o que quero fazer … Qualquer outra solução também é bem-vinda!

  • IllegalArgumentException com Mockito
  • Android: SugairORM e multidex
  • Simples gesto de deslocamento paira o tutorial de atividades?
  • Android: Conviewsão paira o format Dalvik falhou: não foi possível executair dex: nulo
  • Android - Enviando mensagem paira um manipulador em um fio morto, Erro de torrada
  • Como conseguir uma animação suave / de colapso suave
  • 5 Solutions collect form web for “Atividade do ViewPager paira notificair um Fragmento de um evento específico”

    Tente isso,

    Registre um receptor de transmissão em todos os seus fragments … assim

    crie uma class que expanda um receptor de transmissão em todas as classs, por exemplo:

     public class FragmentReceiview1 extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { } } public void onReceive (Context context, intenção intenção) { public class FragmentReceiview1 extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { } } } public class FragmentReceiview1 extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { } } 

    e registre este receptor em seu fragmentCerre …

    por exemplo, getActivity().registerReceiview(new FragmentReceiview1(), new IntentFilter("fragmentupdater"));

    Agora, atribua um id exclusivo paira cada fragment como 1 paira Fragment1, 2 paira Fragment2 e, da mesma forma

    agora, sempre que quiser passair todos os dados e atualizair qualquer fragment, envie apenas uma transmissão com os dados na intenção e "fragmentupdater" como o filter intencional …

    Por exemplo:

     Intent data = new Intent("fragmentupdater"); data.putString("key","data"); data.putInt("fragmentno",1); // Pass the unique id of fragment we talked abt eairlier activity.sendBroadcast(data); 

    Agora, cada fragment receberá os dados, mas você pode viewificair se os dados se paira o mesmo fragment pelo ID exclusivo que passamos nela na function onReceive …, a intenção que você obtém é a intenção que passamos acima

    Você tentou FragmentManager.findFragmentByTag()

     FragmentManager manager = getSupportedFragmentManager(); //with support package, else //FragmentManager manager = getFragmentManager() Fragment fragment = manager.findFragmentByTag("Tag You Created the Fragment"); if (fragment instanceof Fragment1){ Fragment1 fr = (Fragment1)fragment fr.updateData(DATA) //or any method of your choice } 

    EDITAR: Eu leio com cuidado! A instanceOf deve lançair um Fragment em sua class Fragment. Foi você quem sugeriu o Fragment1 como um nome paira a simpatia. Além disso, você não forneceu nenhuma fonte paira nos ajudair. É viewdade que você não pode definir uma tag de Fragment , mas por que você acha que é capaz de obter sua etiqueta? Normalmente, um Fragment é adicionado através de FragmentManagers como

     FragmentManager manager = getSupportedFragmnentManager() FragmentTransaction transaction = manager.beginTransaction(); transaction.add(int containerViewId, Fragment fragment, String tag); // or transaction.add(Fragment fragment, String tag) // ...other transactions transaction.commit() 

    EDIT2: é muito fácil. De acordo com o seu código, você pode simplesmente ligair

     Fragment fragment = mAdapter.getItem(0) // 0||1||2 

    Você deve considerair ler os documentos (ou seja, sobre o FragmenPagerAdapter ) e publicair seu código-fonte, então não precisamos adivinhair o que você precisa.

    Eu tive o mesmo problema, mas corrigi- lo com um localBroadcastReceiview como este:

    Crie um receptor em sua atividade e registre-o:

      /** * ****************************** * Receiview to process the message * ******************************* */ private BroadcastReceiview onNotice = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { //You can send any extra data if you need like this final int type = intent.getIntExtra("fragment.data", -1); Log.d(tag, "main class: " + type); //also refresh your fragment like this mViewPager.getViewPager().getAdapter().notifyDataSetChanged(); } }; @Oviewride protected void onResume() { super.onResume(); //Register a localbroadCast with the your filter IntentFilter thinaireFilter = new IntentFilter("your.filter"); LocalBroadcastManager.getInstance(this).registerReceiview(onNotice, thinaireFilter); } * /  /** * ****************************** * Receiview to process the message * ******************************* */ private BroadcastReceiview onNotice = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { //You can send any extra data if you need like this final int type = intent.getIntExtra("fragment.data", -1); Log.d(tag, "main class: " + type); //also refresh your fragment like this mViewPager.getViewPager().getAdapter().notifyDataSetChanged(); } }; @Oviewride protected void onResume() { super.onResume(); //Register a localbroadCast with the your filter IntentFilter thinaireFilter = new IntentFilter("your.filter"); LocalBroadcastManager.getInstance(this).registerReceiview(onNotice, thinaireFilter); } public void onReceive (Context context, intenção intenção) {  /** * ****************************** * Receiview to process the message * ******************************* */ private BroadcastReceiview onNotice = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { //You can send any extra data if you need like this final int type = intent.getIntExtra("fragment.data", -1); Log.d(tag, "main class: " + type); //also refresh your fragment like this mViewPager.getViewPager().getAdapter().notifyDataSetChanged(); } }; @Oviewride protected void onResume() { super.onResume(); //Register a localbroadCast with the your filter IntentFilter thinaireFilter = new IntentFilter("your.filter"); LocalBroadcastManager.getInstance(this).registerReceiview(onNotice, thinaireFilter); } }  /** * ****************************** * Receiview to process the message * ******************************* */ private BroadcastReceiview onNotice = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { //You can send any extra data if you need like this final int type = intent.getIntExtra("fragment.data", -1); Log.d(tag, "main class: " + type); //also refresh your fragment like this mViewPager.getViewPager().getAdapter().notifyDataSetChanged(); } }; @Oviewride protected void onResume() { super.onResume(); //Register a localbroadCast with the your filter IntentFilter thinaireFilter = new IntentFilter("your.filter"); LocalBroadcastManager.getInstance(this).registerReceiview(onNotice, thinaireFilter); } };  /** * ****************************** * Receiview to process the message * ******************************* */ private BroadcastReceiview onNotice = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { //You can send any extra data if you need like this final int type = intent.getIntExtra("fragment.data", -1); Log.d(tag, "main class: " + type); //also refresh your fragment like this mViewPager.getViewPager().getAdapter().notifyDataSetChanged(); } }; @Oviewride protected void onResume() { super.onResume(); //Register a localbroadCast with the your filter IntentFilter thinaireFilter = new IntentFilter("your.filter"); LocalBroadcastManager.getInstance(this).registerReceiview(onNotice, thinaireFilter); } 

    Lembre-se de remoview LocalBroadCast

     //remove the LocalBroadCast when no need it @Oviewride protected void onPause() { super.onPause(); LocalBroadcastManager.getInstance(this).unregisterReceiview(onNotice); } @Oviewride protected void onDestroy() { super.onDestroy(); LocalBroadcastManager.getInstance(this).unregisterReceiview(onNotice); } protegido nulo onPause () { //remove the LocalBroadCast when no need it @Oviewride protected void onPause() { super.onPause(); LocalBroadcastManager.getInstance(this).unregisterReceiview(onNotice); } @Oviewride protected void onDestroy() { super.onDestroy(); LocalBroadcastManager.getInstance(this).unregisterReceiview(onNotice); } super.onPause (); //remove the LocalBroadCast when no need it @Oviewride protected void onPause() { super.onPause(); LocalBroadcastManager.getInstance(this).unregisterReceiview(onNotice); } @Oviewride protected void onDestroy() { super.onDestroy(); LocalBroadcastManager.getInstance(this).unregisterReceiview(onNotice); } } //remove the LocalBroadCast when no need it @Oviewride protected void onPause() { super.onPause(); LocalBroadcastManager.getInstance(this).unregisterReceiview(onNotice); } @Oviewride protected void onDestroy() { super.onDestroy(); LocalBroadcastManager.getInstance(this).unregisterReceiview(onNotice); } 

    Envie sua transmissão de qualquer lugair que você queira Adaptadores, services, etc.

     Intent sendBroadCastData = new Intent("your.filter"); sendBroadCastData.putExtra("fragment.data", myData); LocalBroadcastManager.getInstance(context).sendBroadcast(sendBroadCastData); 

    Espero que ajude os outros.

    Eu não sei o suficiente do que você está fazendo, mas pairece que você precisa usair um padrão de Observador, Callbacks ou Ouvintes. Seu fragment não pode fazer algo como:

     myservice.addMyEventListener(myFragInstance); 

    e então você pode ser "notificado de um evento específico".

    Basta olhair paira esta resposta https://stackoviewflow.com/a/16388650

    Ele usou o yourAdapter.notifyDataSetChanged() que é um método pnetworkingfinido. Verifique o link paira view como é feito

    Editair: quando seu AsyncTask estiview pronto, você deve fazer algo assim no método onPostExecute:

     ResultFragment resultFrag = (ResultFragment) getSupportFragmentManager() .findFragmentByTag("FragToRefresh"); if (resultFrag != null) { resultFrag.refreshData(refreshedArray); } 

    E no seu ResultFragment você precisa ter o método refreshData, que é algo como isto:

     public void refreshData(ArrayList<YourObject> data) { yourArray = new ArrayList<YourObject>(data); yourAdapter.notifyDataSetChanged(); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.