Commit f5dd48aa authored by Varun Patil's avatar Varun Patil

Add and open BodyFragment from Body Card

parent f327c370
...@@ -4,6 +4,7 @@ import android.content.Context; ...@@ -4,6 +4,7 @@ import android.content.Context;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
...@@ -78,7 +79,13 @@ public class BodyCardFragment extends Fragment { ...@@ -78,7 +79,13 @@ public class BodyCardFragment extends Fragment {
linearLayout.setOnClickListener(new View.OnClickListener() { linearLayout.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Toast.makeText(getContext(), "You clicked " + body.getBodyName(), Toast.LENGTH_SHORT).show(); /* Show the next fragment and destroy the page */
BodyFragment bodyFragment = BodyFragment.newInstance("Dummy", "Dummy");
bodyFragment.setArguments(getArguments());
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.replace(R.id.framelayout_for_fragment, bodyFragment, bodyFragment.getTag());
ft.addToBackStack(bodyFragment.getTag());
ft.commit();
} }
}); });
} }
......
package in.ac.iitb.gymkhana.iitbapp.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import in.ac.iitb.gymkhana.iitbapp.R;
/**
* A simple {@link Fragment} subclass.
* Use the {@link BodyFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class BodyFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
String TAG = "BodyFragment";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
public BodyFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment BodyFragment.
*/
// TODO: Rename and change types and number of parameters
public static BodyFragment newInstance(String param1, String param2) {
BodyFragment fragment = new BodyFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_body, container, false);
}
}
...@@ -101,12 +101,14 @@ public class EventFragment extends BaseFragment implements View.OnClickListener ...@@ -101,12 +101,14 @@ public class EventFragment extends BaseFragment implements View.OnClickListener
eventVenueName.append(", ").append(venue.getVenueName()); eventVenueName.append(", ").append(venue.getVenueName());
} }
for (Body body : event.getEventBodies()) { if(((LinearLayout) getActivity().findViewById(R.id.body_container)).getChildCount() == 0) {
Fragment bodyCardFragment = BodyCardFragment.newInstance(body); for (Body body : event.getEventBodies()) {
getChildFragmentManager().beginTransaction() Fragment bodyCardFragment = BodyCardFragment.newInstance(body);
.add(R.id.body_container, bodyCardFragment, getTag()) getChildFragmentManager().beginTransaction()
.disallowAddToBackStack() .add(R.id.body_container, bodyCardFragment, getTag())
.commit(); .disallowAddToBackStack()
.commit();
}
} }
if (!eventVenueName.toString().equals("")) if (!eventVenueName.toString().equals(""))
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragment.BodyFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment