T
T
TaTIk942016-09-23 18:50:55
Java
TaTIk94, 2016-09-23 18:50:55

How to call a method in an activity from a fragment?

I can not call a method from a fragment in the Main Activity
so I try to call it in the activity

а
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
     int id = item.getItemId();

        if (id == R.id.action_progress_show) {
            progress_menu_item.setActionView(R.layout.menu_item_layout);
 //ТАК Я ЕГО ПЫТАЮСЬ вЫЗвАТЬ в mAİN ACTİVİTY
            TwoFragment  fragment = new TwoFragment();
       fragment. Refress();
   return true;
        }
        return super.onOptionsItemSelected(item);
    }

and this is the method in the fragment
А вОТ МЕТОД вО ФРАГМЕНТЕ 
  }
    public void Refress(){
        mWebView.reload();
        
    }



}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SofroN, 2016-09-26
@SofroN

You are creating a new fragment in the activity instead of looking for the old fragment.
1. add a tag to the fragment in the FragmentTransaction.add
method 2. use the appropriate method to find the fragment
findFragmentByTag
findFragmentById

K
Konstantin Dovnar, 2016-09-23
@SolidlSnake

Understanding this mess is certainly not the most pleasant experience, but as I understand it, you simply create a new fragment in onOptionsItemSelected , but you want to do something in an existing one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question