Note that there are some explanatory texts on larger screens.

plurals
  1. POFragments with Interface class in Android
    primarykey
    data
    text
    <p>I am having issue , how to use the interface class in fragment class. while implementing interface with fragment it not works fine.</p> <p>I have an <strong>1 fragment activity</strong> and <strong>2 fragments</strong>. take as <strong>fragment 1,fragment 2</strong>.</p> <p>By default <strong>fragment 1</strong>(video view its playing video) is inflated in frame layout in half of the page fragment activity. by clicking the button in activity, <strong>fragment 2</strong> is inflated the next half of the page.</p> <p>while clicking the button in <strong>fragment 2</strong> fragment 1 content need a change so i used interface to stop the video in <strong>fragment 1</strong> but it is not working. if i implement the interface in fragment activity its working, but in fragment class it is not working.. help me to do this..</p> <p><strong>fragment activity</strong> </p> <pre><code>public class main extends FragmentActivity implements Interface_Class{ @Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); setContentView(R.layout.activixml); replaceFragment(new fragment1,R.id.fram1); replaceFragment(new fragment2,R.id.fram2); } } public void replaceFragment(Fragment fragment,int layout) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.add(layout, fragment); transaction.commit(); } @Override void setVideoOff(){ system.out.println("inside interface"); } </code></pre> <p><strong>Interface class</strong></p> <pre><code>interface Interface_Class { void setVideoOff() } </code></pre> <p><strong>fragment 1</strong></p> <pre><code> public class feagment1 extends Fragment implements OnCompletionListener,Interface_Class{ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.layout, container, false); videoView = (VideoView) view.findViewById(R.id.videoView); Uri str=Uri.parse(path); // Video path videoView.setVideoURI(str); videoView.requestFocus(); videoView.start(); return view; } } @Override void setVideoOff(){ system.out.println("inside interface"); videoView.stopPlayback(); } </code></pre> <p><strong>fragment 2</strong></p> <pre><code> public class fragment1 extends Fragment{ Interface_Class interface_Class @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.lay1, container, false); interface_Class.setVideoOff(); return view; } @Override public void onAttach(Activity activity) { super.onAttach(activity); try { interface_Class = (Interface_Class) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString()); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload