[Solved] How convert my existing activities to fragment with the same functionality and layout?

You need to create a new fragment, and add the functionality from the activity’s life cycle to the fragment’s life cycle. For example: your activity’s onCreate()’s code should be implemented in onCreateView() of the fragment, off course you’ll have to change some stuff like inflatting the view and returning it instead of calling setContentView(R.layout.id). Implement … Read more

[Solved] How to extend both fragment and AppCompatActivity to a same class?

I have changed your code. Problem was: findViewById(). Activity already have findViewById() method so you can call it in Activity. But Fragment don’t have this method. In Fragment you have to find a View by View.findViewById() method, here View will be the view you are inflating in onCreateView() new ViewPagerAdapter(this). To create a View you … Read more

[Solved] How to open a fragment on click of a button?

In your activity_layout.xml you should add a linearLayout <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:id=”@+id/fragment_container” android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”vertical” > </LinearLayout> Then the rest is up to your code FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View view){ Fragment newCase=new NewCase(); FragmentTransaction transaction=getFragmentManager().beginTransaction(); transaction.replace(R.id.fragment_container,newCase); // give your fragment container id in first parameter transaction.addToBackStack(null); // if written, … Read more

[Solved] How do i do setOnClickListener in Fragment

You can initialize a new onClickListener in for loop. for(int i=0;i<sortableHeaderWrappers.length;i++) { sortableHeaderWrappers[i].setTag((Integer)i); sortableHeaderWrappers[i].setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { //.. place your logic that needs to be executed when click happens. } }) } 0 solved How do i do setOnClickListener in Fragment

[Solved] getActivity() From Fragment to Fragment returning null

adapter.setOnItemClickListner(new DailyMenuFrag()); The new DailyMenuFrag() here is a new fragment and it is not attached to any activity and hence getActivity() returns null. Looks like you should use adapter.setOnItemClickListner(this); instead to use the current DailyMenuFrag instance as item click listener. solved getActivity() From Fragment to Fragment returning null

[Solved] Image slider inside fragment child using ViewFlipper

Since you are using it on fragment replace this line fade_in = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in); fade_out = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_out); with this: fade_in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in); fade_out = AnimationUtils.loadAnimation(this, android.R.anim.fade_out); OR With fade_in = AnimationUtils.loadAnimation(getAppicationContext, android.R.anim.fade_in); fade_out = AnimationUtils.loadAnimation(getAppicationContext, android.R.anim.fade_out); solved Image slider inside fragment child using ViewFlipper

[Solved] How to fix fragments backstack issues in android

Create a singleton named NavigationHandler and add the below functions to it: Function to open MainFragment: public void openMainFragment(FragmentManager fragmentManager, MainFragment fragment){ String backStackName = fragment.getClass().getSimpleName(); fragmentManager.beginTransaction() .replace(R.id.fl_main_container, fragment) .addToBackStack(backStackName) .commit(); } Function to open SubFragment: public void openSubFragment(FragmentManager fragmentManager, SubFragment fragment){ String backStackName = fragment.getClass().getSimpleName(); fragmentManager.popBackStackImmediate(backStackName, POP_BACK_STACK_INCLUSIVE); fragmentManager.beginTransaction() .replace(R.id.fl_main_container, fragment) .addToBackStack(backStackName) .commit(); } For … Read more

[Solved] How can I center the title of navigation drawer application?

Here inside Toolbar inserted a textview with gravity = “center” and disable default title by java. Try with below code : <android.support.design.widget.AppBarLayout app:elevation=”0dp” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:theme=”@style/AppTheme.AppBarOverlay”> <android.support.v7.widget.Toolbar android:id=”@+id/toolbar” android:layout_width=”match_parent” android:layout_height=”?attr/actionBarSize” android:background=”?attr/colorPrimary” app:popupTheme=”@style/AppTheme.PopupOverlay” > <TextView> android:layout_width=”wrap_content” android:textSize=”18dp” android:layout_height=”wrap_content” android:gravity=”center_horizontal” android:text=”Title Here” android:textColor=”@color/white” /> </android.support.v7.widget.Toolbar> </android.support.design.widget.AppBarLayout> java code disable your title : Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); … Read more

[Solved] RecyclerView not displaying in Fragment

You have not Override the Methods which are necessary for fragment. You should find some tutorials on Fragment first,rather using protected method onCreateView you should override its public method. public class RecyclerViewFrag extends Fragment { private List<Person> persons; private RecyclerView rv; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.recyclerview_activity, container, false); … Read more

[Solved] How to get data from fragment to another activity? (Not container activity) [duplicate]

if you’re routing from fragment to another activity, you can put you data into the intent using the putExtra and then receive in the activity using getExtra. Inside the fragment, Intent profileActivityIntent = new Intent(context,ProfileActivity.class); profileActivityIntent.putExtra(“dataKey”,data); startActivity(profileActivityIntent); And then inside the ProfileActivity’s onCreate method, //assuming that data is a string String dataFromFragment = getIntent().getStringExtra(“dataKey”); Log.i(“Data … Read more