first version finished
This commit is contained in:
parent
cceaa97165
commit
6f3a748a06
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
|
2
Readme.txt
Normal file
2
Readme.txt
Normal file
@ -0,0 +1,2 @@
|
||||
Name: Paul LĂdige
|
||||
Matrikel: 15405036
|
@ -1,6 +1,11 @@
|
||||
/**
|
||||
* @author Paul Lödige (Matrikel: 15405036)
|
||||
*/
|
||||
|
||||
package com.ploedige.fragments;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@ -9,13 +14,17 @@ import androidx.fragment.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import java.sql.BatchUpdateException;
|
||||
|
||||
public class Fragment1 extends Fragment {
|
||||
|
||||
Fragment1Listener buttonCallback;
|
||||
|
||||
public interface Fragment1Listener{
|
||||
public void onFragment1ButtonClick();
|
||||
public void onFragment1ButtonClick(String firstName, String lastName);
|
||||
}
|
||||
|
||||
public Fragment1() {
|
||||
@ -30,7 +39,21 @@ public class Fragment1 extends Fragment {
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_1, container, false);
|
||||
View view = inflater.inflate(R.layout.fragment_1, container, false);
|
||||
|
||||
Button jump_btn = (Button) view.findViewById(R.id.jump_btn);
|
||||
jump_btn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
EditText firstName_etxt = (EditText) view.findViewById(R.id.firstName_etxt);
|
||||
EditText lastName_etxt = (EditText) view.findViewById(R.id.lastName_etxt);
|
||||
buttonCallback.onFragment1ButtonClick(
|
||||
firstName_etxt.getText().toString(),
|
||||
lastName_etxt.getText().toString());
|
||||
}
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,8 +66,4 @@ public class Fragment1 extends Fragment {
|
||||
throw new ClassCastException(activity.toString() + "must implement Fragment1Listener");
|
||||
}
|
||||
}
|
||||
|
||||
public void jumpToFragment2(View view){
|
||||
buttonCallback.onFragment1ButtonClick();
|
||||
}
|
||||
}
|
@ -1,16 +1,39 @@
|
||||
/**
|
||||
* @author Paul Lödige (Matrikel: 15405036)
|
||||
*/
|
||||
|
||||
package com.ploedige.fragments;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
public class Fragment2 extends Fragment {
|
||||
public Fragment2() {
|
||||
// Required empty public constructor
|
||||
|
||||
Fragment2Listener buttonCallback;
|
||||
|
||||
public interface Fragment2Listener{
|
||||
public void onFragment2ButtonClick();
|
||||
}
|
||||
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
|
||||
public Fragment2(String firstName, String lastName) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -20,6 +43,34 @@ public class Fragment2 extends Fragment {
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_2, container, false);
|
||||
View view = inflater.inflate(R.layout.fragment_2, container, false);
|
||||
|
||||
//write values to the text views
|
||||
TextView firstName_tv = (TextView) view.findViewById(R.id.firstName_tv);
|
||||
TextView lastName_tv = (TextView) view.findViewById(R.id.lastName_tv);
|
||||
firstName_tv.setText(firstName);
|
||||
lastName_tv.setText(lastName);
|
||||
|
||||
//bind the Frament2Listener to the button
|
||||
Button jump_btn = (Button) view.findViewById(R.id.jump_btn);
|
||||
jump_btn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
buttonCallback.onFragment2ButtonClick();
|
||||
}
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(@NonNull Activity activity) {
|
||||
super.onAttach(activity);
|
||||
try{
|
||||
buttonCallback = (Fragment2Listener) activity;
|
||||
}
|
||||
catch (ClassCastException e){
|
||||
throw new ClassCastException(activity.toString() + "must implement Fragment2Listener");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
/**
|
||||
* @author Paul Lödige (MatrikeL: 15405036)
|
||||
*/
|
||||
|
||||
package com.ploedige.fragments;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
@ -6,7 +10,9 @@ import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
public class MainActivity extends FragmentActivity implements Fragment1.Fragment1Listener {
|
||||
public class MainActivity
|
||||
extends FragmentActivity
|
||||
implements Fragment1.Fragment1Listener, Fragment2.Fragment2Listener {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -24,12 +30,22 @@ public class MainActivity extends FragmentActivity implements Fragment1.Fragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFragment1ButtonClick() {
|
||||
Fragment2 fragment2 = new Fragment2();
|
||||
public void onFragment1ButtonClick(String firstName, String lastName) {
|
||||
Fragment2 fragment2 = new Fragment2(firstName,lastName);
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
|
||||
fragmentTransaction.replace(R.id.fracment_container,fragment2);
|
||||
fragmentTransaction.addToBackStack(null);
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFragment2ButtonClick() {
|
||||
Fragment1 fragment1 = new Fragment1();
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
|
||||
fragmentTransaction.replace(R.id.fracment_container,fragment1);
|
||||
fragmentTransaction.addToBackStack(null);
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
}
|
@ -11,23 +11,65 @@
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name_tv"
|
||||
android:id="@+id/fragmentName_tv"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_marginTop="5mm"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
android:textSize="5mm"
|
||||
android:text="Fragment1" />
|
||||
|
||||
<Button
|
||||
<LinearLayout
|
||||
android:id="@+id/firstName_ll"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@id/name_tv"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/fragmentName_tv">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="First Name:"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/firstName_etxt"
|
||||
android:minWidth="15mm"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/lastName_ll"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/firstName_ll">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="First Name:"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/lastName_etxt"
|
||||
android:minWidth="15mm"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/jump_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@id/lastName_ll"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
android:onClick="jumpToFragment2"
|
||||
android:text="jump to Fragment 2"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
@ -3,12 +3,74 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
tools:context=".Fragment2">
|
||||
|
||||
<!-- TODO: Update blank fragment layout -->
|
||||
<TextView
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/hello_blank_fragment" />
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</FrameLayout>
|
||||
<TextView
|
||||
android:id="@+id/fragmentName_tv"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:layout_marginTop="5mm"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
android:textSize="5mm"
|
||||
android:text="Fragment 2" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/firstName_ll"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/fragmentName_tv">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="First Name:"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/firstName_tv"
|
||||
android:minWidth="15mm"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/lastName_ll"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/firstName_ll">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="First Name:"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lastName_tv"
|
||||
android:minWidth="15mm"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/jump_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@id/lastName_ll"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
android:text="jump to Fragment 1"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</FrameLayout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user