Skip to content
Snippets Groups Projects
Commit 1c062fd0 authored by Rizki Halasan's avatar Rizki Halasan
Browse files

add fragment button

parent 9ae84a85
Branches
Tags
No related merge requests found
...@@ -28,6 +28,7 @@ dependencies { ...@@ -28,6 +28,7 @@ dependencies {
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.squareup.okhttp3:okhttp:3.8.1' compile 'com.squareup.okhttp3:okhttp:3.8.1'
compile 'com.android.support:cardview-v7:26.1.0' compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:recyclerview-v7:26.1.0' compile 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.github.bumptech.glide:glide:4.2.0' compile 'com.github.bumptech.glide:glide:4.2.0'
} }
package com.example.leo.fitnessdiy; package com.example.leo.fitnessdiy;
import android.content.Context; import android.content.Context;
import android.content.Intent;
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.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
/** /**
...@@ -64,7 +66,16 @@ public class ExerciseFragment extends Fragment { ...@@ -64,7 +66,16 @@ public class ExerciseFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
// Inflate the layout for this fragment // Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_exercise, container, false); View view = inflater.inflate(R.layout.fragment_exercise, container, false);
Button plankButton = (Button)view.findViewById(R.id.plank_button);
plankButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(getActivity(), PlankActivity.class);
startActivity(i);
}
});
return view;
} }
// TODO: Rename method, update argument and hook method into UI event // TODO: Rename method, update argument and hook method into UI event
...@@ -105,4 +116,10 @@ public class ExerciseFragment extends Fragment { ...@@ -105,4 +116,10 @@ public class ExerciseFragment extends Fragment {
// TODO: Update argument type and name // TODO: Update argument type and name
void onFragmentInteraction(Uri uri); void onFragmentInteraction(Uri uri);
} }
} }
...@@ -2,6 +2,7 @@ package com.example.leo.fitnessdiy; ...@@ -2,6 +2,7 @@ package com.example.leo.fitnessdiy;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
...@@ -13,6 +14,7 @@ public class HomeActivity extends AppCompatActivity ...@@ -13,6 +14,7 @@ public class HomeActivity extends AppCompatActivity
implements ExerciseFragment.OnFragmentInteractionListener, implements ExerciseFragment.OnFragmentInteractionListener,
HistoryFragment.OnFragmentInteractionListener{ HistoryFragment.OnFragmentInteractionListener{
private FloatingActionButton chatButton;
@Override @Override
public void onFragmentInteraction(Uri uri) { public void onFragmentInteraction(Uri uri) {
...@@ -23,6 +25,8 @@ public class HomeActivity extends AppCompatActivity ...@@ -23,6 +25,8 @@ public class HomeActivity extends AppCompatActivity
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home); setContentView(R.layout.activity_home);
chatButton = findViewById(R.id.chat_button);
chatButton.setImageResource(R.drawable.chat_icon);
} }
public void openHistory(View view) { public void openHistory(View view) {
...@@ -30,10 +34,7 @@ public class HomeActivity extends AppCompatActivity ...@@ -30,10 +34,7 @@ public class HomeActivity extends AppCompatActivity
startActivity(i); startActivity(i);
} }
public void startExcercise(View view) {
Intent i = new Intent(getApplicationContext(), ExerciseActivity.class);
startActivity(i);
}
public void changeFragment(View view){ public void changeFragment(View view){
Fragment fragment; Fragment fragment;
...@@ -45,7 +46,7 @@ public class HomeActivity extends AppCompatActivity ...@@ -45,7 +46,7 @@ public class HomeActivity extends AppCompatActivity
ft.replace(R.id.home_fragment, fragment); ft.replace(R.id.home_fragment, fragment);
ft.commit(); ft.commit();
} }
if(view == findViewById(R.id.exercise_button)){ else if(view == findViewById(R.id.exercise_button)){
fragment = new ExerciseFragment(); fragment = new ExerciseFragment();
FragmentManager fm = getSupportFragmentManager(); FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction(); FragmentTransaction ft = fm.beginTransaction();
...@@ -54,4 +55,7 @@ public class HomeActivity extends AppCompatActivity ...@@ -54,4 +55,7 @@ public class HomeActivity extends AppCompatActivity
} }
} }
public void goToChat(View view) {
}
} }
app/src/main/res/drawable/chat_icon.png

2.11 KiB

...@@ -27,12 +27,19 @@ ...@@ -27,12 +27,19 @@
android:text="@string/exercise" android:text="@string/exercise"
android:onClick="changeFragment"/> android:onClick="changeFragment"/>
</LinearLayout> </LinearLayout>
<fragment <fragment
android:name="com.example.leo.fitnessdiy.ExerciseFragment"
android:id="@+id/home_fragment" android:id="@+id/home_fragment"
android:name="com.example.leo.fitnessdiy.ExerciseFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="471dp" />
/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/chat_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:onClick="goToChat"/>
......
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="com.example.leo.fitnessdiy.ExerciseFragment"> tools:context="com.example.leo.fitnessdiy.ExerciseFragment">
<!-- TODO: Update blank fragment layout --> <Button
<TextView android:id="@+id/plank_button"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:text="EXERCISE" /> android:text="Plank"
/>
</FrameLayout> </FrameLayout>
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